Skip to content

Conversation

@danielhollas
Copy link
Collaborator

We currently use typing_extensions for several important typing features (Self, TypeAlias, ParamSpec), but we only install it for Python versions <3.11. But in practice, many other aiida-core dependencies depend on this package (sqlalchemy, pydantic) so it ends up being installed even on Python 3.14.

uv pip show typing-extensions
Name: typing-extensions
Version: 4.15.0
Location: /home/hollas/atmospec/aiida-core/.venv/lib/python3.14/site-packages
Requires:
Required-by: alembic, asyncssh, beautifulsoup4, mypy, myst-nb, pydantic, pydantic-core, pydata-sphinx-theme, sqlalchemy, typing-inspection

So let's just install it for all Python versions which let's us avoid the awkward try...except import dance.

Split from #7091.

@codecov
Copy link

codecov bot commented Nov 9, 2025

Codecov Report

❌ Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 77.61%. Comparing base (f01c70e) to head (cf71344).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/aiida/common/extendeddicts.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7096      +/-   ##
==========================================
+ Coverage   77.60%   77.61%   +0.01%     
==========================================
  Files         566      566              
  Lines       43549    43535      -14     
==========================================
- Hits        33793    33784       -9     
+ Misses       9756     9751       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@edan-bainglass
Copy link
Member

So let's just install it for all Python versions which let's us avoid the awkward try...except import dance.

To be clear, does installing the extension mean that you can now import them from typing?

@edan-bainglass
Copy link
Member

We currently use typing_extensions for several important typing features (Self, TypeAlias, ParamSpec), but we only install it for Python versions <3.11. But in practice, many other aiida-core dependencies depend on this package (sqlalchemy, pydantic) so it ends up being installed even on Python 3.14.

Is it not correct that for us to move to Python >= 3.11 means that all dependencies MUST support it? And if this is true, they should all have access to Self (for example) from typing. Why do they need typing_extensions?

@danielhollas
Copy link
Collaborator Author

danielhollas commented Nov 9, 2025

To be clear, does installing the extension mean that you can now import them from typing?

No, you always import from typing_extensions. It is a package that backports new typing features for old python version, and it is treated specially by type checkers so for example Self imported fromtyping_extensions has the same meaning as Self from typing

@danielhollas
Copy link
Collaborator Author

Why do they need typing_extensions?

I dunno, they can simply choose to always use the latest typing features that way, for example.

@edan-bainglass
Copy link
Member

edan-bainglass commented Nov 9, 2025

No, you always import from typing_extensions. It is a package that backports new typing features for old python version, and it is treated specially by type checkers so for example Self imported fromtyping_extensions has the same meaning as Self from typing

I'm aware of typing_extensions 😅 I'm asking if somehow installing it means you can now go through typing, which is clearly not the case. I see in your changes that it means we now go through typing_extensions even if our current supported python version provides them via typing. I find this odd. I especially find it odd that we do this not for our own reason, but due to dependencies.

@edan-bainglass
Copy link
Member

@danielhollas I'd like to drop typing_extensions imports entirely once we no longer need them, regardless if we still install it due to dependencies. In other words, our codebase imports should reflect us, not our dependencies. Can we agree on a plan? I think this PR is covering the intermediate stage, but do we agree that once we move to a higher version, we switch the imports to typing?

@danielhollas
Copy link
Collaborator Author

but do we agree that once we move to a higher version, we switch the imports to typing?

Yes, every time we drop a Python version, we should convert the corresponding typing_extensions imports to typing.

like to drop typing_extensions imports entirely

I think dropping the package entirely should not be a goal --- Python typing is still evolving quite a lot, and AiiDA codebase is quite comples so it's likely we will end up using newer features as we expand the typing coverage (I already know about an upcoming feature in 3.15 that we could utilize. Another potentially useful construct is TypeIs)

In other words, our codebase imports should reflect us, not our dependencies.

To be clear, the motivation for this PR was to make our lives simpler. The argument about dependencies was just to say that we currently make it more complicated for ourselves for no benefit.

@danielhollas danielhollas force-pushed the typing-extensions-for-all branch from 37d4dd3 to cf71344 Compare November 11, 2025 05:48
Copy link
Member

@edan-bainglass edan-bainglass left a comment

Choose a reason for hiding this comment

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

LGTM! I somehow feel like this might be an issue later, but maybe I just haven't read enough about it. You (@danielhollas) clearly have, considering the recent deluge of typing PRs 😅 Maybe you could give a short talk on the typing system in an upcoming AiiDA team meeting 🤔

@danielhollas
Copy link
Collaborator Author

Thanks. Not sure what problems you're envisioning but happy to talk about it. :-)

@danielhollas danielhollas merged commit 5c1b2f4 into aiidateam:main Nov 12, 2025
30 of 31 checks passed
@edan-bainglass
Copy link
Member

Thanks. Not sure what problems you're envisioning but happy to talk about it. :-)

Nothing envisioned 😅 Just a hunch, but again, one that is perhaps based in insufficient information 🙂

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants