Skip to content

Conversation

@jscheffl
Copy link
Contributor

@jscheffl jscheffl commented Nov 1, 2025

While implementing #57294 I realized that a couple of more ruff PLW rules might be interesting, this PR enables

See also https://docs.astral.sh/ruff/rules/#warning-plw

@boring-cyborg boring-cyborg bot added backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch kind:documentation provider:amazon AWS/Amazon - related issues labels Nov 1, 2025
@jscheffl jscheffl force-pushed the feature/add-ruff-plw2901-rule branch from 6b58278 to 0eb1c69 Compare November 2, 2025 14:14
Copy link
Member

@pierrejeambrun pierrejeambrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PLW2901 seems good to me, I find it to be a source of error and confusion too.

@jscheffl jscheffl changed the title Enable ruff PLW2901 rule Enable ruff PLW2101,PLW2901,PLW3301 rule Nov 4, 2025
@jscheffl jscheffl force-pushed the feature/add-ruff-plw2901-rule branch from c408eb3 to 0b47076 Compare November 4, 2025 22:43
Comment on lines 2610 to 2611
else:
v = v_in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is a -0 from me since they arguably not only don’t help, but acually make this kind of operations easier to get wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @uranusjr are you referring to this specific case of serialized objects (where we could exclude with # noqa: ... or is it a general concern?

In rework making the codebase compatible I also had one other point in https://github.com/apache/airflow/pull/57700/files#diff-94532ce5cd8778da565396e51f54f7a10078725a1f61656615fbb173b7503fceR1818 where making code compliant made me a hard time.

So do you mean in these specific cases we should exclude rule where it makes code not better? Or do you dislike the rule in general (I think in 90% of cases it prevents failures).

I can also raise a discussion in devlist if you think we should have a larger round of forming an opinion on the rule.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s -0 so I’d not block this, but personally I’m not into this loop variable reuse rule in general.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted the usage in serialized_objects and made it minimal invasive. Hope this improves to have a 0.000001 instead of -0 :-D

@Lee-W
Copy link
Member

Lee-W commented Nov 6, 2025

the descirption was inaccurate, just updated it.

Copy link
Member

@pierrejeambrun pierrejeambrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wei suggestions are good.

Beside naming the general approach sounds good to me.

@jscheffl jscheffl force-pushed the feature/add-ruff-plw2901-rule branch from 0b47076 to a06cd94 Compare November 6, 2025 20:28
@jscheffl
Copy link
Contributor Author

jscheffl commented Nov 6, 2025

the descirption was inaccurate, just updated it.

Thanks @Lee-W for the great feedback! Adjusted names to your very good proposals!

Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nits. But looks great! Thanks!

executor_names_per_team = []
for name in executor_names_config:
if len(split_name := name.split(":")) == 1:
for executor_name_str in executor_names_config:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need the _str here? ignore me if it's needed 👀

Suggested change
for executor_name_str in executor_names_config:
for executor_name in executor_names_config:

for _, module_name, _ in iter_namespace(airflow.serialization.serializers):
module = import_module(module_name)
for serializers in getattr(module, "serializers", ()):
s = serializers if isinstance(serializers, str) else qualname(serializers)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
s = serializers if isinstance(serializers, str) else qualname(serializers)
serializers_qualname = serializers if isinstance(serializers, str) else qualname(serializers)

nit: s or d don't fit my taste. or s_qualname might be better 🤔

c = qualname(c)
if c in _deserializers and _deserializers[c] != name:
raise AttributeError(f"duplicate {c} for stringifiers in {name} and {_stringifiers[c]}")
for stringifiers in getattr(module, "stringifiers", ()):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not something we need to do it this PR. but we maybe can duplicate these few for loop 🤔

Comment on lines +107 to +108
for file_path_raw in find_path_from_directory(plugin_folder_path, ignore_list_file, "glob"):
file_path = Path(file_path_raw)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for file_path_raw in find_path_from_directory(plugin_folder_path, ignore_list_file, "glob"):
file_path = Path(file_path_raw)
for raw_file_path in find_path_from_directory(plugin_folder_path, ignore_list_file, "glob"):
file_path = Path(raw_file_path)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API area:CLI area:DAG-processing area:dev-tools area:Executors-core LocalExecutor & SequentialExecutor area:helm-chart Airflow Helm Chart area:plugins area:providers area:secrets area:serialization backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch kind:documentation provider:amazon AWS/Amazon - related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants