Skip to content

bpo-44791: Fix substitution of ParamSpec in Concatenate with differen… #27518

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

Merged

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Jul 31, 2021

…t parameter expressions

https://bugs.python.org/issue44791

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Aug 31, 2021
@Fidget-Spinner
Copy link
Member

Fidget-Spinner commented Aug 31, 2021

Sorry, I'd forgotten about this. Last I recall we need to amend PEP 612 right? Serhiy would you like me to try write an initial draft (and then you can review it?).

@serhiy-storchaka
Copy link
Member Author

Sure.

What should be clarified:

ParamSpec variables and TypeVar variables are exposed in __parameters__, in order of occurrence. Give examples of Callable and user-defined generics.
Generic types with non-empty __parameters__ are indexable. TypeVar variables can only be substituted with a type expression (type or TypeVar). ParamSpec variables can only be substituted with parameters_expression.
Specifies results of substituting Callable with every of four kinds of parameters_expression.
Specifies results of substituting user-defined generic with every of four kinds of parameters_expression.
Specifies results of substituting ParamSpec in Concatenate.
Substitution ParamSpec with a list of types can lead to __args__ containing list of types. Specify that variables are substituted in lists in __args__.

self.assertEqual(C[int, P2], Concatenate[int, P2])
self.assertEqual(C[int, [str, float]], (int, str, float))
self.assertEqual(C[int, []], (int,))
self.assertEqual(C[int, ...], Concatenate[int, ...])
Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure about this. It can be just [int, ...], although it would create a discrepancy with using ellipsis in Tuple.

@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Sep 1, 2021
@serhiy-storchaka serhiy-storchaka marked this pull request as ready for review January 27, 2022 12:30
@serhiy-storchaka serhiy-storchaka merged commit ecfacc3 into python:main Jan 27, 2022
@miss-islington
Copy link
Contributor

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 27, 2022
…t parameter expressions (pythonGH-27518)

* Substitution with a list of types returns now a tuple of types.
* Substitution with Concatenate returns now a Concatenate with
  concatenated lists of arguments.
* Substitution with Ellipsis is not supported.
(cherry picked from commit ecfacc3)

Co-authored-by: Serhiy Storchaka <[email protected]>
@bedevere-bot
Copy link

GH-30959 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Jan 27, 2022
@serhiy-storchaka serhiy-storchaka deleted the typing-concatenate-subst branch January 27, 2022 12:35
miss-islington added a commit that referenced this pull request Jan 27, 2022
…t parameter expressions (GH-27518)

* Substitution with a list of types returns now a tuple of types.
* Substitution with Concatenate returns now a Concatenate with
  concatenated lists of arguments.
* Substitution with Ellipsis is not supported.
(cherry picked from commit ecfacc3)

Co-authored-by: Serhiy Storchaka <[email protected]>
@gvanrossum
Copy link
Member

Should this be backported?

@serhiy-storchaka
Copy link
Member Author

This PR fixes substitution of a ParamSpec variable with a Concatenate or a list of types. It is not specified by PEP 612, but does not conflict with it.

Substitution with an ellipsis is now an error, because the result cannot be expressed without changing PEP 612. I have opened #30969 for supporting ellipsis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants