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

Commite3a9a3d

Browse files
committed
Merge branch 'master' into fix-annotated-with-function-as-type-keyword-list-parameter
2 parentsb47d21e +583c5f7 commite3a9a3d

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

‎mypy/semanal.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,7 +1794,9 @@ def push_type_args(
17941794
ifself.is_defined_type_param(p.name):
17951795
self.fail(f'"{p.name}" already defined as a type parameter',context)
17961796
else:
1797-
self.add_symbol(p.name,tv,context,no_progress=True,type_param=True)
1797+
assertself.add_symbol(
1798+
p.name,tv,context,no_progress=True,type_param=True
1799+
),"Type parameter should not be discarded"
17981800

17991801
returntvs
18001802

@@ -6830,6 +6832,7 @@ def add_symbol_table_node(
68306832
else:
68316833
# see note in docstring describing None contexts
68326834
self.defer()
6835+
68336836
if (
68346837
existingisnotNone
68356838
andcontextisnotNone
@@ -6849,7 +6852,9 @@ def add_symbol_table_node(
68496852
self.add_redefinition(names,name,symbol)
68506853
ifnot (isinstance(new, (FuncDef,Decorator))andself.set_original_def(old,new)):
68516854
self.name_already_defined(name,context,existing)
6852-
elifnamenotinself.missing_names[-1]and"*"notinself.missing_names[-1]:
6855+
eliftype_paramor (
6856+
namenotinself.missing_names[-1]and"*"notinself.missing_names[-1]
6857+
):
68536858
names[name]=symbol
68546859
ifnotno_progress:
68556860
self.progress=True

‎test-data/unit/check-python312.test‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,43 @@ class C[T]:
12281228
def f[S, S](x: S) -> S: # E: "S" already defined as a type parameter
12291229
return x
12301230

1231+
[case testPEP695TypeVarNameClashNoCrashForwardReference]
1232+
# https://github.com/python/mypy/issues/18507
1233+
from typing import TypeVar
1234+
T = TypeVar("T", bound=Foo) # E: Name "Foo" is used before definition
1235+
1236+
class Foo: ...
1237+
class Bar[T]: ...
1238+
1239+
[case testPEP695TypeVarNameClashNoCrashDeferredSymbol]
1240+
# https://github.com/python/mypy/issues/19526
1241+
T = Unknown # E: Name "Unknown" is not defined
1242+
1243+
class Foo[T]: ...
1244+
class Bar[*T]: ...
1245+
class Baz[**T]: ...
1246+
[builtins fixtures/tuple.pyi]
1247+
1248+
[case testPEP695TypeVarNameClashTypeAlias]
1249+
type Tb = object
1250+
type Ta[Tb] = 'B[Tb]'
1251+
class A[Ta]: ...
1252+
class B[Tb](A[Ta]): ...
1253+
1254+
[case testPEP695TypeVarNameClashStarImport]
1255+
# Similar to
1256+
# https://github.com/python/mypy/issues/19946
1257+
import a
1258+
1259+
[file a.py]
1260+
from b import *
1261+
class Foo[T]: ...
1262+
1263+
[file b.py]
1264+
from a import *
1265+
class Bar[T]: ...
1266+
[builtins fixtures/tuple.pyi]
1267+
12311268
[case testPEP695ClassDecorator]
12321269
from typing import Any
12331270

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp