Skip to content
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

Ignore handling logic for importlib_metadata (mypy, tests/plugins) #20049

Merged
merged 1 commit into from
Dec 14, 2021

Conversation

khalidmammadov
Copy link
Contributor

@khalidmammadov khalidmammadov commented Dec 5, 2021

Part of #19891


^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code change, 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 UPDATING.md.

importlib_metadata_string = 'importlib_metadata'

try:
if sys.version_info[:2] >= (3, 8):
Copy link
Member

Choose a reason for hiding this comment

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

I think we have PY38 constant for that in `airflow': @khalidmammadov .

Also @ashb - I recall discussions we had about it, I think it makes sense to based it on Python version

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, someone (i forget who, maybe Martjin Peiters? sp?) recommended the approach TP says -- always try the third part first, as that API is stable and predictable.)

@uranusjr
Copy link
Member

uranusjr commented Dec 7, 2021

The problem is that importlib.metadata is unstable (the official term is provisional) before 3.10, and not everything in importlib_metadata is available in importlib.metadata. So if we want to switch to, say, the 3.9 version of importlib.metadata, we’d bump the python_version marker in setup.cfg, but after this change we’d also need to change a ton of if-imports due to that change. Try-imports are easier because it’d always try the third-party version first, regardless of the Python version.

If we want to change try-imports to if-imports, it’s probably better to always use importlib_metadata for all versions prior to 3.10, when the stdlib importlib.metadata enters stable state.

Also I believe PY38 would not work because Mypy uses AST detection to perform type-time conditional magic, and would not understand what PY38 means correctly.

@potiuk
Copy link
Member

potiuk commented Dec 7, 2021

The problem is that importlib.metadata is unstable (the official term is provisional) before 3.10

That would explain some of the behaviours seen before :)

@khalidmammadov
Copy link
Contributor Author

The problem is that importlib.metadata is unstable (the official term is provisional) before 3.10, and not everything in importlib_metadata is available in importlib.metadata. So if we want to switch to, say, the 3.9 version of importlib.metadata, we’d bump the python_version marker in setup.cfg, but after this change we’d also need to change a ton of if-imports due to that change. Try-imports are easier because it’d always try the third-party version first, regardless of the Python version.

If we want to change try-imports to if-imports, it’s probably better to always use importlib_metadata for all versions prior to 3.10, when the stdlib importlib.metadata enters stable state.

Also I believe PY38 would not work because Mypy uses AST detection to perform type-time conditional magic, and would not understand what PY38 means correctly.

I will revert and try to fix MyPy issues different way

@khalidmammadov khalidmammadov changed the title Better handling import for importlib_metadata (mypy, tests/plugins) Ignore handling logic for importlib_metadata (mypy, tests/plugins) Dec 7, 2021
@potiuk potiuk merged commit 2f2197d into apache:main Dec 14, 2021
@ashb
Copy link
Member

ashb commented Dec 14, 2021

@khalidmammadov Please read https://cbea.ms/git-commit/ (linked to from our contributing guide) and try to give more useful commit messages in future.

@khalidmammadov
Copy link
Contributor Author

@khalidmammadov Please read https://cbea.ms/git-commit/ (linked to from our contributing guide) and try to give more useful commit messages in future.

Do you mean commit message or PR description/title?

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

Successfully merging this pull request may close these issues.

4 participants