Skip to content

GH-87390: Add remaining tests for PEP 646 - #98267

Merged
JelleZijlstra merged 12 commits into
python:mainfrom
mrahtz:pep646-cleanups
Oct 25, 2022
Merged

JelleZijlstra merged 12 commits into
python:mainfrom
mrahtz:pep646-cleanups

Conversation

@mrahtz

@mrahtz mrahtz commented Oct 14, 2022 •

Copy link
Copy Markdown
Contributor

This PR fixes the last few things from the PEP 646 implementation checklist at #87390 (comment). Specifically:

  • Fix a weird hack we used for star-unpacking in test_genericalias.py before the star-unpacking grammar change was merged
  • Add some more substitution tests (eg [tuple[*Ts, T][str, *tuple[int, ...]])
  • Fix some outdated comments
  • Add tests to typing.py for *ed stuff (again, now that the grammar change is merged)
  • Add tests for get_origin on unpacked stuff

A couple notes:

  • If we were being really exhaustive, we would test the cross product of tuple, Tuple and *, Unpack, for a total of 4 versions of each test, but that would be reeeaaally verbose, so I've gone with just testing the 'new-style' cases (* and tuple) and the 'old-style' cases (Unpack and Tuple).
  • get_origin currently gives different behaviour for *tuple[int] and Unpack[tuple[int]]: tuple in the former case, Unpack in the latter. This is a bit inconsistent, but it seems like the least surprising thing from a user's perspective: if I saw Unpack[something], I'd intuitively expected the origin to be Unpack; and if I saw *tuple[something], I'd expect the origin to be tuple.

Comment thread Lib/test/test_typing.py Outdated
@mrahtz

mrahtz commented Oct 15, 2022

Copy link
Copy Markdown
Contributor Author

Oops, good catch - I think I must have accidentally committed my debug changes, because I found some other things that needed removing. Have fixed them and confirmed that CI is actually passing now :)

@JelleZijlstra JelleZijlstra added the needs backport to 3.11 only security fixes label Oct 15, 2022

@JelleZijlstra JelleZijlstra left a comment

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.

thanks! Just a few small things.

Comment thread Lib/test/test_typing.py Outdated
Comment thread Lib/test/test_typing.py

@gvanrossum gvanrossum left a comment

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.

I'm mostly relying on Jelle's keen eye here. This will have to miss 3.11.0 but will be in 3.11.1.

Comment thread Lib/test/test_typing.py
Comment on lines +595 to +597
For variadic cases, these tests should be regarded as the source of truth,
since we hadn't realised the full complexity of variadic substitution
at the time of finalizing PEP 646. For full discussion, see

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.

If the SC doesn't object maybe we could update the PEP with a more exact specification? Since this was discovered during the beta test period it makes sense to me to update the PEP. Storing a part of a specification permanently in an issue seems iffy to me (plenty of tests refer to the issue that caused the test to be added, but the wording here makes me think that the situation here is different -- this is effectively part of the specification).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure - if the SC is fine with it, I'd be happy to write this up in the PEP properly.

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.

@mrahtz From the SC issue I gather the following:

  • We should add these tests (they'll land in 3.11.1, that's fine)
  • We (you) should write the PEP update and submit it to the SC for formal approval

I expect the SC approval for the PEP updates should be easy to obtain.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, great. I'll work on the PEP updates as soon as I have some time.

@gvanrossum

Copy link
Copy Markdown
Member

@JelleZijlstra Are you happy with these tests? Then you can merge them.

@JelleZijlstra
JelleZijlstra self-requested a review October 24, 2022 16:47
@JelleZijlstra

Copy link
Copy Markdown
Member

Probably, I'll take another look tonight and merge if I'm happy.

@JelleZijlstra JelleZijlstra self-assigned this Oct 25, 2022
@JelleZijlstra
JelleZijlstra merged commit cb95cc2 into python:main Oct 25, 2022
@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @mrahtz for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@miss-islington

Copy link
Copy Markdown
Contributor

Sorry, @mrahtz and @JelleZijlstra, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker cb95cc24efecf32ad035318867b065a2b042d25a 3.11

JelleZijlstra pushed a commit to JelleZijlstra/cpython that referenced this pull request Oct 25, 2022
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>.
(cherry picked from commit cb95cc2)

Co-authored-by: Matthew Rahtz <matthew.rahtz@gmail.com>
@bedevere-bot

Copy link
Copy Markdown

GH-98667 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Oct 25, 2022
JelleZijlstra added a commit that referenced this pull request Oct 26, 2022
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>.
Co-authored-by: Matthew Rahtz <matthew.rahtz@gmail.com>

(cherry picked from commit cb95cc2)
@mrahtz mrahtz mentioned this pull request Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Tests in the Lib/test dir topic-typing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants