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

gh-102615: Fix type vars substitution of `collections.abc.Callable` and custom generics with `ParamSpec` by sobolevn · Pull Request #102681 · python/cpython · GitHub

/ cpython Public

gh-102615: Fix type vars substitution of collections.abc.Callable and custom generics with ParamSpec - #102681

Closed
sobolevn wants to merge 2 commits into
python:mainfrom
sobolevn:new-expand
Closed

gh-102615: Fix type vars substitution of collections.abc.Callable and custom generics with ParamSpec#102681
sobolevn wants to merge 2 commits into
python:mainfrom
sobolevn:new-expand

Conversation

sobolevn commented Mar 14, 2023
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Member

I would prefer to create two PRs to fix #102615

  1. This one that fixes a bug with Callable and custom generics with ParamSpec
  2. gh-102615: Use list instead of tuple in repr of paramspec #102637 to change the repr

Comment thread Lib/_collections_abc.py Outdated

Fidget-Spinner commented Mar 14, 2023
edited
Loading

Copy link
Copy Markdown
Member

I encountered another bug, the __repr__ needs to be updated as well:

>>> ca.Callable[[int, P], int][P][int]
collections.abc.Callable[[int, (<class 'int'>,)], int]

EDIT: THIS MIGHT NOT BE A BUG, AS ITS AN INVALID USE. PLEASE IGNORE THIS @sobolevn

sobolevn commented Mar 14, 2023
edited
Loading

Copy link
Copy Markdown
Member Author

@Fidget-Spinner I would like to move all repr related problems to another PR if that possible :)

I've only touched params substitution here.

sobolevn commented Mar 14, 2023
edited
Loading

Copy link
Copy Markdown
Member Author

Wait a moment, this is not about repr, this is an __args__ containing a tuple 😒

>>> ca.Callable[[int, P], int][P].__args__
(<class 'int'>, ~P, <class 'int'>)
>>> ca.Callable[[int, P], int][P][int].__args__
(<class 'int'>, (<class 'int'>,), <class 'int'>)

rhettinger removed their request for review March 14, 2023 13:42

sobolevn commented Mar 14, 2023
edited
Loading

Copy link
Copy Markdown
Member Author

Funny thing, I just removed this code from _collections_abc.py as an experiment:

if (len(self.__parameters__) == 1
                and _is_param_expr(self.__parameters__[0])
                and item and not _is_param_expr(item[0])):
            item = (item,)

All tests still pass :)

🤯

AlexWaygood left a comment
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think the runtime is correct in raising TypeError for these situations, actually: see #102615 (comment)

Maybe instead, we should focus on improving the error message, so that users get more specific feedback on why the substitution is being disallowed? Though if it adds too much complexity to the code, I probably wouldn't bother with it.

Copy link
Copy Markdown
Member Author

I am going to close this for now, I will add new tests in other PRs, because this one has a big unrelated history.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Representation of ParamSpecs at runtime compared to Callable

4 participants


Back | FazBrowse Home | New Git URL