Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2171b6f

Browse files
authored
Delete Instance.invalid (#20861)
`Instance` is like the hottest type ever. Having a whole attribute there to tweak some rare/niche edge case seems really wasteful. I think we should delete it. (I also delete 1 line of dead code while I am at it.)
1 parent 87e9425 commit 2171b6f

5 files changed

Lines changed: 1 addition & 10 deletions

File tree

mypy/checkexpr.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4885,9 +4885,6 @@ class LongName(Generic[T]): ...
48854885
"""
48864886
if alias.python_3_12_type_alias:
48874887
return self.type_alias_type_type()
4888-
if isinstance(alias.target, Instance) and alias.target.invalid: # type: ignore[misc]
4889-
# An invalid alias, error already has been reported
4890-
return AnyType(TypeOfAny.from_error)
48914888
# If this is a generic alias, we set all variables to `Any`.
48924889
# For example:
48934890
# A = List[Tuple[T, T]]

mypy/copytype.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def visit_deleted_type(self, t: DeletedType) -> ProperType:
6565

6666
def visit_instance(self, t: Instance) -> ProperType:
6767
dup = Instance(t.type, t.args, last_known_value=t.last_known_value)
68-
dup.invalid = t.invalid
6968
return self.copy_common(t, dup)
7069

7170
def visit_type_var(self, t: TypeVarType) -> ProperType:

mypy/typeanal.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,7 +2097,6 @@ def fix_instance(
20972097
# Already wrong arg count error, don't emit missing type parameters error as well.
20982098
disallow_any = False
20992099
t.args = ()
2100-
arg_count = 0
21012100

21022101
args: list[Type] = [*(t.args[:max_tv_count])]
21032102
any_type: AnyType | None = None
@@ -2550,7 +2549,6 @@ def validate_instance(t: Instance, fail: MsgCallback, empty_tuple_index: bool) -
25502549
t,
25512550
code=codes.TYPE_ARG,
25522551
)
2553-
t.invalid = True
25542552
return False
25552553
return True
25562554

mypy/types.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,9 +1627,6 @@ def __init__(
16271627
self.args = tuple(args)
16281628
self.type_ref: str | None = None
16291629

1630-
# True if recovered after incorrect number of type arguments error
1631-
self.invalid = False
1632-
16331630
# This field keeps track of the underlying Literal[...] value associated with
16341631
# this instance, if one is known.
16351632
#

test-data/unit/check-generics.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ main:13:1: error: Value of type variable "T" of "SameA" cannot be "str"
11261126
class A: ...
11271127
Bad = A[int] # type: ignore
11281128

1129-
reveal_type(Bad) # N: Revealed type is "Any"
1129+
reveal_type(Bad) # N: Revealed type is "def () -> __main__.A"
11301130
[out]
11311131

11321132
[case testSubscriptionOfBuiltinAliases]

0 commit comments

Comments
 (0)