Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[3.14] Address invalid inputs of TypeAliasType#477

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

Daraan
Copy link
Contributor

@DaraanDaraan commentedOct 1, 2024
edited
Loading

I've prepared this draft which contains two changes:

  • typing_extensions.TypeAliasType not raising TypeError if a non-tuple is passed compared to thetyping variant.

  • backport of
    gh-124787: FixTypeAliasType and incorrecttype_params cpython#124795 for <=3.11(needs to be accepted first)

  • Await merge and change if necessary

  • Afterwards fix correct python versions. I currently assume the backport is valid in 3.14.

  • Should backport for 3.12-13 be made? Yes.

It should maybe noted that for 3.12.0-3.12.7 thetyping.TypeAliasType variant does not contain this stricter backport.
I do not think that there is a necessity to do a backport for 3.12 and it will likely do more harm (I did not test it).

Daraan added a commit to Daraan/typing_extensions that referenced this pull requestOct 1, 2024
@JelleZijlstra
Copy link
Member

I merged the upstream PR but did not backport it to 3.12 and 3.13, so this should now be ready to go. I'll push some buttons to do so and then review the code.

@JelleZijlstraJelleZijlstra marked this pull request as ready for reviewOctober 21, 2024 12:29
for case, msg in invalid_cases:
with self.subTest(type_params=case):
if TYPING_3_12_0 and sys.version_info < (3, 14):
self.skipTest("No backport for 3.12 and 3.13 requires cpython PR #124795")

Choose a reason for hiding this comment

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

We decided not to backport in CPython. This test should be changed so that typing_extensions does provide the backport.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

AsTypeAliasType cannot be subclassed, I tried to do a minimal invasive workaround with__new__ to return thetyping variant but this fails the pickling check.

Do you know a workaround or is this__new__ method not something to pursue further?


At the moment the <3.12 backport would pass the test and would work as a full backport for 3.12 & 3.13.

Choose a reason for hiding this comment

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

I think we can just use the pre-3.12 variant on 3.12 and 3.13.

Daraan and AlexWaygood reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Guess with annotationlib (likely?) comming it needs a backport anyway.

parameters = []
for type_param in type_params:
if not isinstance(type_param, (TypeVar, TypeVarTuple, ParamSpec)):

Choose a reason for hiding this comment

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

This needs to accept both the typing and typing_extensions versions of these classes, which are different on some versions. Test this.

Copy link
ContributorAuthor

@DaraanDaraanOct 21, 2024
edited
Loading

Choose a reason for hiding this comment

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

Yes, I saw this too, but realized that_TypeVarLikeMeta handlesisinstance check.test_type_params_compatibilitytest_type_var_compatibility and theother methods test this.

@DaraanDaraan marked this pull request as draftOctober 21, 2024 18:09
@DaraanDaraan marked this pull request as ready for reviewOctober 22, 2024 16:54
@DaraanDaraan changed the title[needs upstream first] Address invalid inputs of TypeAliasType[3.14] Address invalid inputs of TypeAliasTypeOct 22, 2024
((1,), "Expected a type param, got 1"),
((str,), f"Expected a type param, got {str!r}"),
# Unpack backport behaves like TypeVar in some cases

Choose a reason for hiding this comment

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

What "some cases" exactly? Ideally this should be accepted.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Updated the comment for more clarity. Asisinstance(Unpack[Ts], TypeVar) is True in Python < 3.12Unpack would not raise here without the additional check and would be accepted as a type parameter.

fortype_paramintype_params:if (notisinstance(type_param, (TypeVar,TypeVarTuple,ParamSpec))or_is_unpack(type_param)        ):raiseTypeError(f"Expected a type param, got{type_param!r}")

@JelleZijlstraJelleZijlstra merged commit139ac68 intopython:mainOct 25, 2024
21 checks passed
@DaraanDaraan deleted the TypeAliasType/invalid_param_spec branchOctober 25, 2024 07:01
@DaraanDaraan restored the TypeAliasType/invalid_param_spec branchOctober 25, 2024 15:22
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@JelleZijlstraJelleZijlstraJelleZijlstra approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@Daraan@JelleZijlstra

[8]ページ先頭

©2009-2025 Movatter.jp