Skip to content

Commit

Permalink
fix code style to mypy guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanDaemon committed Oct 14, 2020
1 parent a9d0996 commit 40b5aed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 4 additions & 2 deletions mypy/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,15 @@ def get_column(self) -> int:
} # type: Final

_nongen_builtins = {'builtins.tuple': 'typing.Tuple',
'builtins.enumerate': ''} # type: Final
'builtins.enumerate': ''} # type: Final
_nongen_builtins.update((name, alias) for alias, name in type_aliases.items())

def get_nongen_builtins(python_version):

def get_nongen_builtins(python_version: Tuple[int, int]) -> Dict[str, str]:
# After 3.9 with pep585 generic builtins are allowed.
return _nongen_builtins if python_version < (3, 9) else {}


RUNTIME_PROTOCOL_DECOS = ('typing.runtime_checkable',
'typing_extensions.runtime',
'typing_extensions.runtime_checkable') # type: Final
Expand Down
16 changes: 11 additions & 5 deletions mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ def try_analyze_special_unbound_type(self, t: UnboundType, fullname: str) -> Opt

def get_omitted_any(self, typ: Type, fullname: Optional[str] = None) -> AnyType:
disallow_any = not self.is_typeshed_stub and self.options.disallow_any_generics
return get_omitted_any(disallow_any, self.fail, self.note, typ, self.options.python_version, fullname)
return get_omitted_any(disallow_any, self.fail, self.note, typ,
self.options.python_version, fullname)

def analyze_type_with_type_info(
self, info: TypeInfo, args: Sequence[Type], ctx: Context) -> Type:
Expand Down Expand Up @@ -1028,7 +1029,8 @@ def fix_instance(t: Instance, fail: MsgCallback, note: MsgCallback,
fullname = None # type: Optional[str]
else:
fullname = t.type.fullname
any_type = get_omitted_any(disallow_any, fail, note, t, python_version, fullname, unexpanded_type)
any_type = get_omitted_any(disallow_any, fail, note, t, python_version, fullname,
unexpanded_type)
t.args = (any_type,) * len(t.type.type_vars)
return
# Invalid number of type parameters.
Expand Down Expand Up @@ -1287,7 +1289,8 @@ def make_optional_type(t: Type) -> Type:
return UnionType([t, NoneType()], t.line, t.column)


def fix_instance_types(t: Type, fail: MsgCallback, note: MsgCallback, python_version: Tuple[int, int]) -> None:
def fix_instance_types(t: Type, fail: MsgCallback, note: MsgCallback,
python_version: Tuple[int, int]) -> None:
"""Recursively fix all instance types (type argument count) in a given type.
For example 'Union[Dict, List[str, int]]' will be transformed into
Expand All @@ -1297,12 +1300,15 @@ def fix_instance_types(t: Type, fail: MsgCallback, note: MsgCallback, python_ver


class InstanceFixer(TypeTraverserVisitor):
def __init__(self, fail: MsgCallback, note: MsgCallback, python_version: Tuple[int, int]) -> None:
def __init__(
self, fail: MsgCallback, note: MsgCallback, python_version: Tuple[int, int]
) -> None:
self.fail = fail
self.note = note
self.python_version = python_version

def visit_instance(self, typ: Instance) -> None:
super().visit_instance(typ)
if len(typ.args) != len(typ.type.type_vars):
fix_instance(typ, self.fail, self.note, disallow_any=False, python_version=self.python_version, use_generic_error=True)
fix_instance(typ, self.fail, self.note, disallow_any=False,
python_version=self.python_version, use_generic_error=True)

0 comments on commit 40b5aed

Please sign in to comment.