Skip to content

Commit

Permalink
process comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrugman committed Dec 9, 2023
1 parent b823ce9 commit feea90e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
14 changes: 7 additions & 7 deletions refurb/checks/readability/fluid_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

@dataclass
class ErrorInfo(Error):
"""
https://towardsdatascience.com/the-unreasonable-effectiveness-of-method-chaining-in-pandas-15c2109e3c69
r"""When an API has a Fluent Interface (the ability to chain multiple calls together), you should chain those calls
instead of repeatedly assigning and using the value.
Sometimes a return statement can be written more succinctly:
Bad:
```
```python
def get_tensors(device: str) -> torch.Tensor:
a = torch.ones(2, 1)
a = a.long()
Expand All @@ -44,7 +44,7 @@ def process(file_name: str):
Good:
```
```python
def get_tensors(device: str) -> torch.Tensor:
a = (
torch.ones(2, 1)
Expand All @@ -66,8 +66,8 @@ def process(file_name: str):
```
"""

name = "fluid-interface"
code = 999
name = "use-fluid-interface"
code = 184
categories = ("readability",)


Expand All @@ -93,7 +93,7 @@ def check_stmts(stmts: list[Statement], errors: list[Error]) -> None:
for stmt in stmts:
match stmt:
case AssignmentStmt(lvalues=[NameExpr(name=name)], rvalue=rvalue):
if last != "" and f"{last}'" == name and check_call(rvalue):
if last and f"{last}'" == name and check_call(rvalue):
errors.append(
ErrorInfo.from_node(
stmt,
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions test/data/err_184.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test/data/err_184.py:53:5 [FURB184]: Assignment statements should be chained
test/data/err_184.py:54:5 [FURB184]: Assignment statements should be chained
test/data/err_184.py:61:5 [FURB184]: Assignment statements should be chained
test/data/err_184.py:64:5 [FURB184]: Assignment statements should be chained

0 comments on commit feea90e

Please sign in to comment.