Skip to content

Conversation

@ashb
Copy link
Member

@ashb ashb commented Nov 11, 2024

Pyright (the type engine powering VSCode's python extension) doesn't treat
airflow as a namespace package because of the airflow/__init__.py and it
doesn't want to/can't support detecting the __path__ = ... method of making
it an explicit namespace package, so we are left with no option but to create
Yet Another Stub File.

Tested by pytting reveal_type(FAB_VERSION); reveal_type(TaskSDKDag) inside
_upgrade_outdated_dag_access_control in airflow/model/dag.py -- before
this change it was reporting both as Unknown.

@ashb
Copy link
Member Author

ashb commented Nov 11, 2024

cc @JDarDagran

Copy link
Contributor

@JDarDagran JDarDagran left a comment

Choose a reason for hiding this comment

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

As for VSCode user with Pylance enabled - it fixed the issue. Thank you a lot @ashb 🚀

@ashb
Copy link
Member Author

ashb commented Nov 12, 2024

Okay sadly we can't do this. By creating this empty file pycharm thinks airflow is an empty module.

Okay, think I might have it fixed now.

@ashb ashb force-pushed the fix-vscode-ns-packages branch 2 times, most recently from c3c9847 to a8f5231 Compare November 12, 2024 09:54
Pyright (the type engine powering VSCode's python extension) doesn't treat
`airflow` as a namespace package because of the `airflow/__init__.py` and it
doesn't want to/can't support detecting the `__path__ = ...` method of making
it an explicit namespace package, so we are left with no option but to create
Yet Another Stub File.

Tested by pytting `reveal_type(FAB_VERSION); reveal_type(TaskSDKDag)` inside
`_upgrade_outdated_dag_access_control` in `airflow/model/dag.py` -- before
this change it was reporting both as Unknown.

And to continue to keep Pycharm happy we have to have the `__path__` stanzas
without future annotations in all the "empty" files.

Ugly, but at least it works
@ashb ashb force-pushed the fix-vscode-ns-packages branch from a8f5231 to 73eb25b Compare November 12, 2024 10:29
@ashb ashb requested a review from potiuk as a code owner November 12, 2024 11:11
# Similarly we need _a_ file for task_sdk too
mkdir -p ./task_sdk/src/airflow/sdk/
touch ./task_sdk/src/airflow/__init__.py
touch ./task_sdk/src/airflow/sdk/__init__.py
Copy link
Member Author

Choose a reason for hiding this comment

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

This path was okay before, but since I added exclude = ["src/airflow/__init__.py"] in this PR this path now needs to change.

Copy link
Contributor

@amoghrajesh amoghrajesh left a comment

Choose a reason for hiding this comment

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

Pycharm test works as expected as discussed offline. LGTM

@ashb
Copy link
Member Author

ashb commented Nov 12, 2024

Static check failure unrelated and will be fixed by #43923

Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

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

Cool. Getting it right with PyCharm, VSCode namespace packages and static checks and CLI seems like an interesting game :)

@ashb ashb merged commit 86aa5ef into main Nov 12, 2024
@ashb ashb deleted the fix-vscode-ns-packages branch November 12, 2024 12:09
sunank200 pushed a commit to astronomer/airflow that referenced this pull request Nov 12, 2024
Pyright (the type engine powering VSCode's python extension) doesn't treat
`airflow` as a namespace package because of the `airflow/__init__.py` and it
doesn't want to/can't support detecting the `__path__ = ...` method of making
it an explicit namespace package, so we are left with no option but to create
Yet Another Stub File.

Tested by pytting `reveal_type(FAB_VERSION); reveal_type(TaskSDKDag)` inside
`_upgrade_outdated_dag_access_control` in `airflow/model/dag.py` -- before
this change it was reporting both as Unknown.

And to continue to keep Pycharm happy we have to have the `__path__` stanzas
without future annotations in all the "empty" files.

Ugly, but at least it works
ellisms pushed a commit to ellisms/airflow that referenced this pull request Nov 13, 2024
Pyright (the type engine powering VSCode's python extension) doesn't treat
`airflow` as a namespace package because of the `airflow/__init__.py` and it
doesn't want to/can't support detecting the `__path__ = ...` method of making
it an explicit namespace package, so we are left with no option but to create
Yet Another Stub File.

Tested by pytting `reveal_type(FAB_VERSION); reveal_type(TaskSDKDag)` inside
`_upgrade_outdated_dag_access_control` in `airflow/model/dag.py` -- before
this change it was reporting both as Unknown.

And to continue to keep Pycharm happy we have to have the `__path__` stanzas
without future annotations in all the "empty" files.

Ugly, but at least it works
kaxil added a commit to astronomer/airflow that referenced this pull request Nov 15, 2024
same as Task SDK change in apache#43899 -- but for providers
kaxil added a commit that referenced this pull request Nov 15, 2024
same as Task SDK change in #43899 -- but for providers
kandharvishnu pushed a commit to kandharvishnu/airflow that referenced this pull request Nov 19, 2024
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request May 27, 2025
same as Task SDK change in apache/airflow#43899 -- but for providers

GitOrigin-RevId: eed59f1e96f590edcc95327b2874dd95bb8137ca
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Sep 23, 2025
same as Task SDK change in apache/airflow#43899 -- but for providers

GitOrigin-RevId: eed59f1e96f590edcc95327b2874dd95bb8137ca
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Oct 20, 2025
same as Task SDK change in apache/airflow#43899 -- but for providers

GitOrigin-RevId: eed59f1e96f590edcc95327b2874dd95bb8137ca
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.

6 participants