Skip to content

Third-party tests failed on Thu Apr 17 2025 #586

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

Closed
github-actions bot opened this issue Apr 17, 2025 · 10 comments · Fixed by #587
Closed

Third-party tests failed on Thu Apr 17 2025 #586

github-actions bot opened this issue Apr 17, 2025 · 10 comments · Fixed by #587

Comments

@github-actions
Copy link

Run listed here: https://github.com/python/typing_extensions/actions/runs/14506991058

@Viicos
Copy link
Contributor

Viicos commented Apr 17, 2025

Old dirty code from Pydantic v1, I'll fix it.

@JelleZijlstra
Copy link
Member

Thanks! This would still mean that future releases of typing-extensions will be incompatible with any currently released version of Pydantic, right? It might be worth re-adding _AnnotatedAlias (maybe just re-export it from typing) to avoid disrupting users who don't want to immediately upgrade Pydantic.

@Viicos
Copy link
Contributor

Viicos commented Apr 17, 2025

This would still mean that future releases of typing-extensions will be incompatible with any currently released version of Pydantic, right?

Only Pydantic V1, so the impact is limited (and while we still rely on a couple private typing members such as _GenericAlias, it was a bad idea to rely on _AnnotatedAlias as it could be easily avoided). I'll make a new Pydantic V1 release today and while users could be using an old V1 version, upgrading is really straightforward as only compatibility fixes were released for a while now.

@JelleZijlstra
Copy link
Member

Ah right, it would only be if users explicitly import pydantic.v1.

Looks like litestar also relies on _AnnotatedAlias (https://github.com/python/typing_extensions/actions/runs/14506991058/job/40698118697), cc @provinzkraut.

I feel like that's enough reason to re-add the private symbol to typing-extensions (though I'd still encourage you to avoid using it).

JelleZijlstra added a commit to JelleZijlstra/typing_extensions that referenced this issue Apr 17, 2025
JelleZijlstra added a commit that referenced this issue Apr 17, 2025
@provinzkraut
Copy link
Contributor

provinzkraut commented Apr 17, 2025

I feel like that's enough reason to re-add the private symbol to typing-extensions (though I'd still encourage you to avoid using it).

Mh. We use it to check if something is Annotated. The typing docs only say

At runtime, the metadata associated with an Annotated type can be retrieved via the __metadata__ attribute

but that is brittle. Many things can have a __metadata__ attribute, and we'd like to avoid false positives here. If we shouldn't use this (or its stdlib equivalent), what would be the canonical way to check if something is Annotated and extract its associated metadata in a safe way?

I'd also prefer not to use undocumented private types, but currently don't know of a better alternative.

@JelleZijlstra
Copy link
Member

Like this:

>>> import typing
>>> typing.get_origin(typing.Annotated[int, 1])
typing.Annotated
>>> typing.get_args(typing.Annotated[int, 1])
(<class 'int'>, 1)

get_origin() and get_args() are the answer to most introspection needs in my experience.

@Viicos
Copy link
Contributor

Viicos commented Apr 17, 2025

@provinzkraut you can also rely on our typing-inspection library as discussed earlier in one of litestar's PR. It does not use anything private from typing, and avoids many common issues (checking against both typing and typing_extensions variants, working around CPython bugs, etc).

@AlexWaygood
Copy link
Member

@provinzkraut we also have some docs on robust strategies to introspect typing constructs here: https://typing-extensions.readthedocs.io/en/latest/#runtime-use-of-types

@provinzkraut
Copy link
Contributor

Like this:

>>> import typing
>>> typing.get_origin(typing.Annotated[int, 1])
typing.Annotated
>>> typing.get_args(typing.Annotated[int, 1])
(<class 'int'>, 1)

get_origin() and get_args() are the answer to most introspection needs in my experience.

Heh, thanks for the reminder. This comment made me re-visit our code again, and it turns out the util that has failed in the run above isn't actually used anymore, and we've migrated away from using _AnnotatedAlias everywhere else some time ago. I had just forgotten about this :)

We should be able to just remove the offending code, so there will be no compatibility issue from our side anymore.

@JelleZijlstra
Copy link
Member

Great, thanks! I think it still makes sense to keep the name defined in typing-extensions for some time so users can safely upgrade typing-extensions without having to worry about upgrading other libraries, and because there are surely more people using _AnnotatedAlias than the two of you.

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 a pull request may close this issue.

4 participants