airflow icon indicating copy to clipboard operation
airflow copied to clipboard

Cope with Pycharm's oddity in detecting namespace packages

Open ashb opened this issue 1 year ago • 6 comments

Without the __path__ assignment being the very first line of the file (including before any import) it doesn't detect this correctly.

ashb avatar Oct 17 '24 13:10 ashb

@shahar1 @kaxil Could one of you test if this fixes it please?

ashb avatar Oct 17 '24 13:10 ashb

@shahar1 @kaxil Could one of you test if this fixes it please?

Yup, works now

kaxil avatar Oct 17 '24 13:10 kaxil

Yeah I tried in #43081 but could not make it work. Mypy/Python is not happy about it and raise a SyntaxError

vincbeck avatar Oct 17 '24 14:10 vincbeck

https://youtrack.jetbrains.com/issue/PY-46690/Allow-all-imports-from-the-same-named-packages-if-path-manipulation-in-init-is-detected is the closest current issue I've found, but not exactly the same

ashb avatar Oct 17 '24 20:10 ashb

Let's just exclude airflow.__init__.py from automatically adding from __future__ import annotations and convert it back to use "regular" typing.

We've done that for Pydantic classes before and still doing it for some test files https://github.com/apache/airflow/blob/main/pyproject.toml#L355

potiuk avatar Oct 18 '24 00:10 potiuk

I added alternative implementation - and it seems to work for me https://github.com/apache/airflow/pull/43173 - just by removing from future and adding ignore rules from ruff seem to do the job as I suspected. Actually airflow/__init__.py did not require any change beceause it does not use postponed evaluation of types PEP563 at all.

potiuk avatar Oct 18 '24 17:10 potiuk

Closing this one. It's already fixed.

potiuk avatar Oct 29 '24 21:10 potiuk