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

Commitb013cc0

Browse files
authored
SupportTypeAliasType in a class scope (#17038)
Fixes#16614 (comment)
1 parent61a4900 commitb013cc0

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

‎mypy/semanal.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3657,7 +3657,7 @@ def check_and_set_up_type_alias(self, s: AssignmentStmt) -> bool:
36573657
returnFalse
36583658

36593659
non_global_scope=self.typeorself.is_func_scope()
3660-
ifnotpep_613andisinstance(rvalue,RefExpr)andnon_global_scope:
3660+
ifnotpep_613andnotpep_695andisinstance(rvalue,RefExpr)andnon_global_scope:
36613661
# Fourth rule (special case): Non-subscripted right hand side creates a variable
36623662
# at class and function scopes. For example:
36633663
#

‎test-data/unit/check-type-aliases.test‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,11 @@ TestType = TypeAliasType("TestType", Union[int, str])
10741074
x: TestType = 42
10751075
y: TestType = 'a'
10761076
z: TestType = object() # E: Incompatible types in assignment (expression has type "object", variable has type "Union[int, str]")
1077+
1078+
class A:
1079+
ClassAlias = TypeAliasType("ClassAlias", int)
1080+
xc: A.ClassAlias = 1
1081+
yc: A.ClassAlias = "" # E: Incompatible types in assignment (expression has type "str", variable has type "int")
10771082
[builtins fixtures/tuple.pyi]
10781083

10791084
[case testTypeAliasTypeInvalid]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp