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

Add support for PEP695 TypeAliasType #11140

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

dev-loki
Copy link

Fixes: #10719
Discussed (by others) in: #10662

Adds support for PEP695.

Sidesupport (please check if intended!): Only loads *_py312 files for python3.12 and later, as only the test introduces syntax not compatible for python < 3.12.

def some_complex_function():
    return 42
    
type DependedVariable = Annotated[int, some_complex_function]

Using DependedVariable in route dependencies will now work :).

@dev-loki
Copy link
Author

Kind of unhappy with the amount of hoopsI jump through to not let coverage/pytest really see the test code, as it is a true SyntaxError in all python Version before 3.12.

Maybe there is a better idea?

Comment on lines +3 to +4
if sys.version_info < (3, 12):
collect_ignore_glob = ["*_py312.py"]
Copy link
Author

Choose a reason for hiding this comment

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

Shall we add that to the previous versions too?

Comment on lines +10 to +12
needs_py312 = pytest.mark.skipif(
sys.version_info < (3, 12), reason="requires python3.12+"
)
Copy link
Author

Choose a reason for hiding this comment

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

Tbh I would prefer adding that as a custom mark:

In conftest.py:

import sys

def pytest_runtest_setup(item):
    for mark in item.iter_markers():
        if mark.name == 'py312' and sys.version_info < (3, 12):
            pytest.skip("Cannot run on python versin < 3.12")
        ...

This would change the test code to:

import pytest

@pytest.mark.py312
def test_only_executed_on_python_312_and_above():
    assert sys.version_info >= (3, 12)

@tiangolo tiangolo added feature New feature or request p3 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request p3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Annotated dependencies are interpreted incorrectly when using PEP 695-style type alias.
2 participants