Skip to content

Commit 3e435f2

Browse files
authored
Some minor cleanups and fixes to work with mypyc (#5473)
1 parent fc45d17 commit 3e435f2

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

mypy/nodes.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
from abc import abstractmethod
55
from collections import OrderedDict, defaultdict
66
from typing import (
7-
Any, TypeVar, List, Tuple, cast, Set, Dict, Union, Optional, Callable, Sequence
7+
Any, TypeVar, List, Tuple, cast, Set, Dict, Union, Optional, Callable, Sequence,
88
)
99

1010
MYPY = False
1111
if MYPY:
12-
from typing import DefaultDict
12+
from typing import DefaultDict, ClassVar
1313

1414
import mypy.strconv
1515
from mypy.util import short_type
@@ -48,7 +48,7 @@ def get_column(self) -> int:
4848
return self.column
4949

5050

51-
if False:
51+
if MYPY:
5252
# break import cycle only needed for mypy
5353
import mypy.types
5454

@@ -630,11 +630,10 @@ def deserialize(cls, data: JsonDict) -> 'FuncDef':
630630
# NOTE: ret.info is set in the fixup phase.
631631
ret.arg_names = data['arg_names']
632632
ret.arg_kinds = data['arg_kinds']
633-
# Mark these as 'None' so that future uses will trigger an error
634-
_dummy = None # type: Any
635-
ret.arguments = _dummy
636-
ret.max_pos = _dummy
637-
ret.min_args = _dummy
633+
# Leave these uninitialized so that future uses will trigger an error
634+
del ret.arguments
635+
del ret.max_pos
636+
del ret.min_args
638637
return ret
639638

640639

@@ -1243,8 +1242,6 @@ def accept(self, visitor: ExpressionVisitor[T]) -> T:
12431242
class ComplexExpr(Expression):
12441243
"""Complex literal"""
12451244

1246-
value = 0.0j
1247-
12481245
def __init__(self, value: complex) -> None:
12491246
super().__init__()
12501247
self.value = value
@@ -2166,7 +2163,7 @@ class is generic then it will be a type constructor of higher kind.
21662163
FLAGS = [
21672164
'is_abstract', 'is_enum', 'fallback_to_any', 'is_named_tuple',
21682165
'is_newtype', 'is_protocol', 'runtime_protocol'
2169-
]
2166+
] # type: ClassVar[List[str]]
21702167

21712168
def __init__(self, names: 'SymbolTable', defn: ClassDef, module_name: str) -> None:
21722169
"""Initialize a TypeInfo."""

mypy/server/astmerge.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,6 @@ def visit_union_type(self, typ: UnionType) -> None:
419419
def fixup(self, node: SN) -> SN:
420420
if node in self.replacements:
421421
new = self.replacements[node]
422-
# TODO: This may be unnecessary?
423-
new.__dict__ = node.__dict__
424422
return cast(SN, new)
425423
return node
426424

mypy/types.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
from collections import OrderedDict
77
from typing import (
88
Any, TypeVar, Dict, List, Tuple, cast, Generic, Set, Optional, Union, Iterable, NamedTuple,
9-
Callable, Sequence, Iterator
9+
Callable, Sequence, Iterator,
1010
)
1111

12+
MYPY = False
13+
if MYPY:
14+
from typing import ClassVar
15+
1216
import mypy.nodes
1317
from mypy import experiments
1418
from mypy.nodes import (
@@ -24,8 +28,6 @@
2428

2529
JsonDict = Dict[str, Any]
2630

27-
MYPY = False
28-
2931
# If we import type_visitor in the middle of the file, mypy breaks, and if we do it
3032
# at the top, it breaks at runtime because of import cycle issues, so we do it at different
3133
# times in different places.
@@ -92,7 +94,7 @@ class TypeVarId:
9294
meta_level = 0 # type: int
9395

9496
# Class variable used for allocating fresh ids for metavariables.
95-
next_raw_id = 1 # type: int
97+
next_raw_id = 1 # type: ClassVar[int]
9698

9799
def __init__(self, raw_id: int, meta_level: int = 0) -> None:
98100
self.raw_id = raw_id

0 commit comments

Comments
 (0)