FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Allow type parameters without default values to follow those with default values in some situations by AlexWaygood · Pull Request #392 · python/typing_extensions · GitHub

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

Merged
JelleZijlstra merged 7 commits into
python:mainfrom
AlexWaygood:default-before-nondefault-2
May 16, 2024
Merged

Allow type parameters without default values to follow those with default values in some situations#392
JelleZijlstra merged 7 commits into
python:mainfrom
AlexWaygood:default-before-nondefault-2

Conversation

AlexWaygood commented May 14, 2024
edited
Loading

Copy link
Copy Markdown
Member

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).

Copy link
Copy Markdown
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 commented May 16, 2024
edited
Loading

Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown
Member

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

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL