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

Fix completion/linting/type checking with VSCode/pyright #43899

Merged
merged 2 commits into from
Nov 12, 2024

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 requested a review from potiuk as a code owner November 12, 2024 11:11
@@ -660,7 +660,7 @@ function install_airflow() {

# 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
77 of 78 checks passed
@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
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