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

fix: fail check if not enough or too many types provided to `TypeAlia…#18308

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

@bzoracler
Copy link
Contributor

…sType()`

Fixes#18307 by failing a type alias call check if the number of positional arguments isn't exactly 2 (one for the type name as a literal string, one for the target type to alias).

Before:

fromtyping_extensionsimportTypeAliasTypeT1=TypeAliasType("T1",int,str)# Silently passes and uses `int` as the target type, should be an errorT2=TypeAliasType("T2")# Crashes

After:

T1=TypeAliasType("T1",int,str)# E: Too many positional arguments for "TypeAliasType"T2=TypeAliasType("T2")# E: Missing positional argument "value" in call to "TypeAliasType"

The error messages above are propagated from a check with theTypeAliasType constructor definition from the stubs, so no further special-casing is necessary:

classTypeAliasType:def__init__(self,name:str,value:Any,*,type_params:tuple[TypeVar|ParamSpec|TypeVarTuple, ...]= ()        )->None: ...

@github-actions

This comment has been minimized.

Copy link
Member

@JelleZijlstraJelleZijlstra left a comment

Choose a reason for hiding this comment

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

Thanks, could you add a test that exercises this code path?

To find the place to add a test, grep for TypeAliasType among the.test files.

@github-actions
Copy link
Contributor

According tomypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@JelleZijlstraJelleZijlstra merged commit1f9317f intopython:masterDec 19, 2024
19 checks passed
@bzoraclerbzoracler deleted the fix/typealias-num-args branchDecember 19, 2024 21:01
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.

Incompletely defining aTypeAliasType causes mypy to crash

2 participants

@bzoracler@JelleZijlstra

[8]ページ先頭

©2009-2025 Movatter.jp