New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable TCH004
and TCH005
rules
#35475
Conversation
Move to draft for prevent accidentally merge into the main |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
Need to check that nothing actually broken after this changes. But seems like it should fix some methods in:
|
Yeah.. Circular imports ImportError: cannot import name 'Job' from partially initialized module 'airflow.jobs.job' (most likely due to a circular import) (/opt/airflow/airflow/jobs/job.py) Well local imports then |
from kubernetes.client import models as k8s | ||
from kubernetes.client import models as k8s # noqa: TCH004 | ||
|
||
from airflow.providers.cncf.kubernetes.pod_generator import PodGenerator | ||
from airflow.providers.cncf.kubernetes.pod_generator import PodGenerator # noqa: TCH004 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The real dark magic happen here
airflow/airflow/serialization/serialized_objects.py
Lines 446 to 448 in 64a64ab
elif var.__class__.__name__ == "V1Pod" and _has_kubernetes() and isinstance(var, k8s.V1Pod): | |
json_pod = PodGenerator.serialize_pod(var) | |
return cls._encode(json_pod, type_=DAT.POD) |
That is only affect k8s
and PodGenerator
so better exclude only this lines from check rather then entire module
eb7e4b6
to
a745ed4
Compare
Follow-up: #35465 (comment)
Enable two additional rules TCH rules in ruff
TCH004
- Check that import only use as type annotation, has false positive alarms so I think that is why it under the--unsafe-fixes
TCH005
- Remove emptyTYPE_CHECKING
block^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rst
or{issue_number}.significant.rst
, in newsfragments.