This release adds one new check and a bunch of bug fixes!
Add use-fluent-interface
(FURB184)
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:
def get_tensors(device: str) -> torch.Tensor:
t1 = torch.ones(2, 1)
t2 = t1.long()
t3 = t2.to(device)
return t3
def process(file_name: str):
common_columns = ["col1_renamed", "col2_renamed", "custom_col"]
df = spark.read.parquet(file_name)
df = df \
.withColumnRenamed('col1', 'col1_renamed') \
.withColumnRenamed('col2', 'col2_renamed')
df = df \
.select(common_columns) \
.withColumn('service_type', F.lit('green'))
return df
Good:
def get_tensors(device: str) -> torch.Tensor:
t3 = (
torch.ones(2, 1)
.long()
.to(device)
)
return t3
def process(file_name: str):
common_columns = ["col1_renamed", "col2_renamed", "custom_col"]
df = (
spark.read.parquet(file_name)
.withColumnRenamed('col1', 'col1_renamed')
.withColumnRenamed('col2', 'col2_renamed')
.select(common_columns)
.withColumn('service_type', F.lit('green'))
)
return df
Thank you to @sbrugman for implementing this new check!
What's Changed
- Fix FURB183 false positive when using custom formatter by @dosisod in #315
- Fix FURB118
operator.contains
false positive, improve error messages by @dosisod in #317 - Initial implementation for fluid interface check by @sbrugman in #287
- Fix: false negative in FURB111 by @sbrugman in #313
- Fix FURB115 being emitted when using
len(x)
with non-boolean operators by @dosisod in #319
New Contributors
Full Changelog: v1.25.0...v1.26.0