Skip to content

Add support for PEP 695 type aliases#14898

Draft
loewexy wants to merge 1 commit into
pyca:mainfrom
loewexy:asn1-add-support-for-pep695-type-aliases
Draft

Add support for PEP 695 type aliases#14898
loewexy wants to merge 1 commit into
pyca:mainfrom
loewexy:asn1-add-support-for-pep695-type-aliases

Conversation

@loewexy
Copy link
Copy Markdown
Contributor

@loewexy loewexy commented May 22, 2026

Fixes #14892

However, currently the implementation is missing tests for that specific feature.

@loewexy loewexy marked this pull request as draft May 22, 2026 12:16
@alex
Copy link
Copy Markdown
Member

alex commented May 22, 2026

@facutuesca do you have a) opinions on if this is the right place for this? b) thoughts on how to test?

@loewexy
Copy link
Copy Markdown
Contributor Author

loewexy commented May 22, 2026

I have to setup a complete development environment for cryptography to test so that i can also run the linters and stuff, however i will not manage to do this today. But I will try to do it next week. Otherwise also feel free to use my draft and update it as you like.

Comment thread src/cryptography/hazmat/asn1/asn1.py Outdated
Comment on lines +111 to +112
if sys.version_info >= (3,12):
while isinstance(field_type, typing.TypeAliasType):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This could also be present in previous versions by using typing_extensions.TypeAliasType. See the top of the file for how we handle conditionally importing from typing vs typing_extensions for different Python versions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

While I'd assume cryptography can't easily add a new dependency, we provide and use https://typing-inspection.pydantic.dev/latest/ in Pydantic. It takes care of all the possible variants that are easy to miss when dealing with typing objects (in particular TypeAliasType, see our implementation). The usage guide provides useful information too.

@facutuesca
Copy link
Copy Markdown
Contributor

facutuesca commented May 22, 2026

b) thoughts on how to test?

If the only concern about testing is the newer Python versions needed for the feature (mentioned here), see my review comment about supporting typing_extensions.TypeAliasType for older Python versions.

@loewexy loewexy force-pushed the asn1-add-support-for-pep695-type-aliases branch from 531e6c1 to a1c7274 Compare May 27, 2026 06:38
@loewexy
Copy link
Copy Markdown
Contributor Author

loewexy commented May 27, 2026

So no i have a local test setup an fixed the linter errors. On my machine also the existing tests run without a problem. However adding a test for that case an maybe also the edge cases in combination with annotated would make sense.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

asn1: Support type aliases

4 participants