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

Allow type parameters without default values to follow those with default values in some situations #392

Merged
merged 7 commits into from
May 16, 2024

Conversation

AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented May 14, 2024

This is a backport of python/cpython#118774. The implementation feels unbelievably hacky (we're looking up the value of a local variable in frame two levels up the call stack), but I can't see another way of doing it. I initially tried an approach where we monkeypatched _GenericAlias.__init__, but this didn't work: see python/cpython#118774 (comment).

@JelleZijlstra
Copy link
Member

Working on the merge conflict. I think I wouldn't want to use a _getframe-based hack, but I'll have to think of an alternative.

@AlexWaygood
Copy link
Member Author

AlexWaygood commented May 16, 2024

I think I wouldn't want to use a _getframe-based hack, but I'll have to think of an alternative.

Yeah. I think we definitely need to make some change to our current implementation at typing_extensions, since currently we're strictly more prohibitive than the CPython implementation, and that's not great. If we really don't like this hack, though, I think it would be okay (though not ideal) to be strictly more lenient than the CPython implementation -- simply not check the order of the parameters under any circumstances.

@JelleZijlstra
Copy link
Member

Thinking about it more, I think this is OK. It's well localized and only affects old versions of typing.

@JelleZijlstra JelleZijlstra merged commit 479ac33 into python:main May 16, 2024
18 checks passed
@AlexWaygood AlexWaygood deleted the default-before-nondefault-2 branch May 16, 2024 01:02
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