Skip to content

Commit 46e1d35

Browse files
authored
Eliminate all mypyc warnings when compiling mypy (#6638)
This was a big obstacle that made me reluctant to set up CI.
1 parent ffb3ce9 commit 46e1d35

File tree

9 files changed

+21
-16
lines changed

9 files changed

+21
-16
lines changed

mypy/checkexpr.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,7 @@ def infer_overload_return_type(self,
14951495
# We try returning a precise type if we can. If not, we give up and just return 'Any'.
14961496
if all_same_types(return_types):
14971497
return return_types[0], inferred_types[0]
1498-
elif all_same_types(erase_type(typ) for typ in return_types):
1498+
elif all_same_types([erase_type(typ) for typ in return_types]):
14991499
return erase_type(return_types[0]), erase_type(inferred_types[0])
15001500
else:
15011501
return self.check_call(callee=AnyType(TypeOfAny.special_form),
@@ -3113,8 +3113,9 @@ def visit_generator_expr(self, e: GeneratorExpr) -> Type:
31133113
def check_generator_or_comprehension(self, gen: GeneratorExpr,
31143114
type_name: str,
31153115
id_for_messages: str,
3116-
additional_args: List[Type] = []) -> Type:
3116+
additional_args: Optional[List[Type]] = None) -> Type:
31173117
"""Type check a generator expression or a list comprehension."""
3118+
additional_args = additional_args or []
31183119
with self.chk.binder.frame_context(can_skip=True, fall_through=0):
31193120
self.check_for_comp(gen)
31203121

@@ -3734,8 +3735,7 @@ def any_causes_overload_ambiguity(items: List[CallableType],
37343735
return False
37353736

37363737

3737-
def all_same_types(types: Iterable[Type]) -> bool:
3738-
types = list(types)
3738+
def all_same_types(types: List[Type]) -> bool:
37393739
if len(types) == 0:
37403740
return True
37413741
return all(is_same_type(t, types[0]) for t in types[1:])

mypy/fastparse.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
from mypy.options import Options
4141

4242
try:
43+
# pull this into a final variable to make mypyc be quiet about the
44+
# the default argument warning
45+
PY_MINOR_VERSION = sys.version_info[1] # type: Final
46+
4347
# Check if we can use the stdlib ast module instead of typed_ast.
4448
if sys.version_info >= (3, 8):
4549
import ast as ast3
@@ -64,7 +68,7 @@
6468
)
6569

6670
def ast3_parse(source: Union[str, bytes], filename: str, mode: str,
67-
feature_version: int = sys.version_info[1]) -> AST:
71+
feature_version: int = PY_MINOR_VERSION) -> AST:
6872
return ast3.parse(source, filename, mode,
6973
type_comments=True, # This works the magic
7074
feature_version=feature_version)
@@ -92,7 +96,7 @@ def ast3_parse(source: Union[str, bytes], filename: str, mode: str,
9296
)
9397

9498
def ast3_parse(source: Union[str, bytes], filename: str, mode: str,
95-
feature_version: int = sys.version_info[1]) -> AST:
99+
feature_version: int = PY_MINOR_VERSION) -> AST:
96100
return ast3.parse(source, filename, mode, feature_version=feature_version)
97101

98102
# These don't exist before 3.8

mypy/ipc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
MYPY = False
1616
if MYPY:
1717
from typing import Type
18+
from typing_extensions import Final
1819

1920
from types import TracebackType
2021

@@ -179,7 +180,7 @@ def __exit__(self,
179180

180181
class IPCServer(IPCBase):
181182

182-
BUFFER_SIZE = 2**16
183+
BUFFER_SIZE = 2**16 # type: Final
183184

184185
def __init__(self, name: str, timeout: Optional[float] = None) -> None:
185186
if sys.platform == 'win32':

mypy/messages.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ def incompatible_conditional_function_def(self, defn: FuncDef) -> None:
921921
def cannot_instantiate_abstract_class(self, class_name: str,
922922
abstract_attributes: List[str],
923923
context: Context) -> None:
924-
attrs = format_string_list("'%s'" % a for a in abstract_attributes)
924+
attrs = format_string_list(["'%s'" % a for a in abstract_attributes])
925925
self.fail("Cannot instantiate abstract class '%s' with abstract "
926926
"attribute%s %s" % (class_name, plural_s(abstract_attributes),
927927
attrs),
@@ -1507,8 +1507,7 @@ def plural_s(s: Union[int, Sequence[Any]]) -> str:
15071507
return ''
15081508

15091509

1510-
def format_string_list(s: Iterable[str]) -> str:
1511-
lst = list(s)
1510+
def format_string_list(lst: List[str]) -> str:
15121511
assert len(lst) > 0
15131512
if len(lst) == 1:
15141513
return lst[0]

mypy/newsemanal/typeanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ def __init__(self) -> None:
12191219
super().__init__(self.combine_lists_strategy)
12201220

12211221
def query_types(self, types: Iterable[Type]) -> List[Type]:
1222-
return self.strategy(t.accept(self) for t in types) + list(types)
1222+
return self.strategy([t.accept(self) for t in types]) + list(types)
12231223

12241224
@classmethod
12251225
def combine_lists_strategy(cls, it: Iterable[List[Type]]) -> List[Type]:

mypy/nodes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2996,8 +2996,8 @@ def __str__(self) -> str:
29962996
return '\n'.join(a)
29972997

29982998
def copy(self) -> 'SymbolTable':
2999-
return SymbolTable((key, node.copy())
3000-
for key, node in self.items())
2999+
return SymbolTable([(key, node.copy())
3000+
for key, node in self.items()])
30013001

30023002
def serialize(self, fullname: str) -> JsonDict:
30033003
data = {'.class': 'SymbolTable'} # type: JsonDict

mypy/report.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,8 @@ def __init__(self, reports: Reports, output_dir: str) -> None:
419419
# XML doesn't like control characters, but they are sometimes
420420
# legal in source code (e.g. comments, string literals).
421421
# Tabs (#x09) are allowed in XML content.
422-
control_fixer = str.maketrans(''.join(chr(i) for i in range(32) if i != 9), '?' * 31)
422+
control_fixer = str.maketrans(
423+
''.join(chr(i) for i in range(32) if i != 9), '?' * 31) # type: Final
423424

424425
def on_file(self,
425426
tree: MypyFile,

mypy/stubdoc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
class ArgSig:
2525
"""Signature info for a single argument."""
2626

27-
_TYPE_RE = re.compile(r'^[a-zA-Z_][\w\[\], ]*(\.[a-zA-Z_][\w\[\], ]*)*$')
27+
_TYPE_RE = re.compile(r'^[a-zA-Z_][\w\[\], ]*(\.[a-zA-Z_][\w\[\], ]*)*$') # type: Final
2828

2929
def __init__(self, name: str, type: Optional[str] = None, default: bool = False):
3030
self.name = name

mypy/typeanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ def __init__(self) -> None:
12431243
super().__init__(self.combine_lists_strategy)
12441244

12451245
def query_types(self, types: Iterable[Type]) -> List[Type]:
1246-
return self.strategy(t.accept(self) for t in types) + list(types)
1246+
return self.strategy([t.accept(self) for t in types]) + list(types)
12471247

12481248
@classmethod
12491249
def combine_lists_strategy(cls, it: Iterable[List[Type]]) -> List[Type]:

0 commit comments

Comments
 (0)