Skip to content

Commit 1beed9a

Browse files
authored
Remove a lot of unused code (#11698)
1 parent ef07896 commit 1beed9a

14 files changed

+47
-131
lines changed

mypy/checker.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
from mypy.message_registry import ErrorMessage
6464
from mypy.subtypes import (
6565
is_subtype, is_equivalent, is_proper_subtype, is_more_precise,
66-
restrict_subtype_away, is_subtype_ignoring_tvars, is_callable_compatible,
66+
restrict_subtype_away, is_callable_compatible,
6767
unify_generic_callable, find_member
6868
)
6969
from mypy.constraints import SUPERTYPE_OF
@@ -956,7 +956,7 @@ def check_func_def(self, defn: FuncItem, typ: CallableType, name: Optional[str])
956956
if isclass:
957957
ref_type = mypy.types.TypeType.make_normalized(ref_type)
958958
erased = get_proper_type(erase_to_bound(arg_type))
959-
if not is_subtype_ignoring_tvars(ref_type, erased):
959+
if not is_subtype(ref_type, erased, ignore_type_params=True):
960960
note = None
961961
if (isinstance(erased, Instance) and erased.type.is_protocol or
962962
isinstance(erased, TypeType) and
@@ -1737,7 +1737,7 @@ def erase_override(t: Type) -> Type:
17371737

17381738
if len(order) == len(original.items) and order != sorted(order):
17391739
self.msg.overload_signature_incompatible_with_supertype(
1740-
name, name_in_super, supertype, override, node)
1740+
name, name_in_super, supertype, node)
17411741
emitted_msg = True
17421742

17431743
if not emitted_msg:

mypy/git.py

-6
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,3 @@ def is_dirty(dir: str) -> bool:
3030
"""Check whether a git repository has uncommitted changes."""
3131
output = subprocess.check_output(["git", "status", "-uno", "--porcelain"], cwd=dir)
3232
return output.strip() != b""
33-
34-
35-
def has_extra_files(dir: str) -> bool:
36-
"""Check whether a git repository has untracked files."""
37-
output = subprocess.check_output(["git", "clean", "--dry-run", "-d"], cwd=dir)
38-
return output.strip() != b""

mypy/join.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
)
1212
from mypy.maptype import map_instance_to_supertype
1313
from mypy.subtypes import (
14-
is_subtype, is_equivalent, is_subtype_ignoring_tvars, is_proper_subtype,
14+
is_subtype, is_equivalent, is_proper_subtype,
1515
is_protocol_implementation, find_member
1616
)
1717
from mypy.nodes import INVARIANT, COVARIANT, CONTRAVARIANT
@@ -72,7 +72,7 @@ def join_instances(self, t: Instance, s: Instance) -> ProperType:
7272
assert new_type is not None
7373
args.append(new_type)
7474
result: ProperType = Instance(t.type, args)
75-
elif t.type.bases and is_subtype_ignoring_tvars(t, s):
75+
elif t.type.bases and is_subtype(t, s, ignore_type_params=True):
7676
result = self.join_instances_via_supertype(t, s)
7777
else:
7878
# Now t is not a subtype of s, and t != s. Now s could be a subtype
@@ -402,8 +402,7 @@ def visit_typeddict_type(self, t: TypedDictType) -> ProperType:
402402
if (is_equivalent(s_item_type, t_item_type) and
403403
(item_name in t.required_keys) == (item_name in self.s.required_keys))
404404
])
405-
mapping_value_type = join_type_list(list(items.values()))
406-
fallback = self.s.create_anonymous_fallback(value_type=mapping_value_type)
405+
fallback = self.s.create_anonymous_fallback()
407406
# We need to filter by items.keys() since some required keys present in both t and
408407
# self.s might be missing from the join if the types are incompatible.
409408
required_keys = set(items.keys()) & t.required_keys & self.s.required_keys

mypy/meet.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,7 @@ def visit_typeddict_type(self, t: TypedDictType) -> ProperType:
629629
assert t_item_type is not None
630630
item_list.append((item_name, t_item_type))
631631
items = OrderedDict(item_list)
632-
mapping_value_type = join.join_type_list(list(items.values()))
633-
fallback = self.s.create_anonymous_fallback(value_type=mapping_value_type)
632+
fallback = self.s.create_anonymous_fallback()
634633
required_keys = t.required_keys | self.s.required_keys
635634
return TypedDictType(items, required_keys, fallback)
636635
elif isinstance(self.s, Instance) and is_subtype(t, self.s):

mypy/messages.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ def incompatible_operator_assignment(self, op: str,
807807

808808
def overload_signature_incompatible_with_supertype(
809809
self, name: str, name_in_super: str, supertype: str,
810-
overload: Overloaded, context: Context) -> None:
810+
context: Context) -> None:
811811
target = self.override_target(name, name_in_super, supertype)
812812
self.fail('Signature of "{}" incompatible with {}'.format(
813813
name, target), context, code=codes.OVERRIDE)
@@ -1399,9 +1399,6 @@ def redundant_condition_in_comprehension(self, truthiness: bool, context: Contex
13991399
def redundant_condition_in_if(self, truthiness: bool, context: Context) -> None:
14001400
self.redundant_expr("If condition", truthiness, context)
14011401

1402-
def redundant_condition_in_assert(self, truthiness: bool, context: Context) -> None:
1403-
self.redundant_expr("Condition in assert", truthiness, context)
1404-
14051402
def redundant_expr(self, description: str, truthiness: bool, context: Context) -> None:
14061403
self.fail("{} is always {}".format(description, str(truthiness).lower()),
14071404
context, code=codes.REDUNDANT_EXPR)
@@ -1855,8 +1852,7 @@ def format_type(typ: Type, verbosity: int = 0) -> str:
18551852

18561853

18571854
def format_type_bare(typ: Type,
1858-
verbosity: int = 0,
1859-
fullnames: Optional[Set[str]] = None) -> str:
1855+
verbosity: int = 0) -> str:
18601856
"""
18611857
Convert a type to a relatively short string suitable for error messages.
18621858

mypy/plugins/singledispatch.py

-9
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,6 @@ def call_singledispatch_function_after_register_argument(ctx: MethodContext) ->
201201
return ctx.default_return_type
202202

203203

204-
def rename_func(func: CallableType, new_name: CallableType) -> CallableType:
205-
"""Return a new CallableType that is `function` with the name of `new_name`"""
206-
if new_name.name is not None:
207-
signature_used = func.with_name(new_name.name)
208-
else:
209-
signature_used = func
210-
return signature_used
211-
212-
213204
def call_singledispatch_function_callback(ctx: MethodSigContext) -> FunctionLike:
214205
"""Called for functools._SingleDispatchCallable.__call__"""
215206
if not isinstance(ctx.type, Instance):

mypy/semanal.py

-16
Original file line numberDiff line numberDiff line change
@@ -4979,19 +4979,6 @@ def add_exports(self, exp_or_exps: Union[Iterable[Expression], Expression]) -> N
49794979
if isinstance(exp, StrExpr):
49804980
self.all_exports.append(exp.value)
49814981

4982-
def check_no_global(self,
4983-
name: str,
4984-
ctx: Context,
4985-
is_overloaded_func: bool = False) -> None:
4986-
if name in self.globals:
4987-
prev_is_overloaded = isinstance(self.globals[name], OverloadedFuncDef)
4988-
if is_overloaded_func and prev_is_overloaded:
4989-
self.fail("Nonconsecutive overload {} found".format(name), ctx)
4990-
elif prev_is_overloaded:
4991-
self.fail("Definition of '{}' missing 'overload'".format(name), ctx)
4992-
else:
4993-
self.name_already_defined(name, ctx, self.globals[name])
4994-
49954982
def name_not_defined(self, name: str, ctx: Context, namespace: Optional[str] = None) -> None:
49964983
incomplete = self.is_incomplete_namespace(namespace or self.cur_mod_id)
49974984
if (namespace is None
@@ -5121,9 +5108,6 @@ def fail(self,
51215108
assert ctx is not None, msg
51225109
self.errors.report(ctx.get_line(), ctx.get_column(), msg, blocker=blocker, code=code)
51235110

5124-
def fail_blocker(self, msg: str, ctx: Context) -> None:
5125-
self.fail(msg, ctx, blocker=True)
5126-
51275111
def note(self, msg: str, ctx: Context, code: Optional[ErrorCode] = None) -> None:
51285112
if not self.in_checked_function():
51295113
return

mypy/semanal_shared.py

+1-23
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
from mypy_extensions import trait
88

99
from mypy.nodes import (
10-
Context, SymbolTableNode, MypyFile, ImportedName, FuncDef, Node, TypeInfo, Expression, GDEF,
10+
Context, SymbolTableNode, FuncDef, Node, TypeInfo, Expression,
1111
SymbolNode, SymbolTable
1212
)
13-
from mypy.util import correct_relative_import
1413
from mypy.types import (
1514
Type, FunctionLike, Instance, TupleType, TPDICT_FB_NAMES, ProperType, get_proper_type
1615
)
@@ -179,27 +178,6 @@ def is_func_scope(self) -> bool:
179178
raise NotImplementedError
180179

181180

182-
def create_indirect_imported_name(file_node: MypyFile,
183-
module: str,
184-
relative: int,
185-
imported_name: str) -> Optional[SymbolTableNode]:
186-
"""Create symbol table entry for a name imported from another module.
187-
188-
These entries act as indirect references.
189-
"""
190-
target_module, ok = correct_relative_import(
191-
file_node.fullname,
192-
relative,
193-
module,
194-
file_node.is_package_init_file())
195-
if not ok:
196-
return None
197-
target_name = '%s.%s' % (target_module, imported_name)
198-
link = ImportedName(target_name)
199-
# Use GDEF since this refers to a module-level definition.
200-
return SymbolTableNode(GDEF, link)
201-
202-
203181
def set_callable_name(sig: Type, fdef: FuncDef) -> ProperType:
204182
sig = get_proper_type(sig)
205183
if isinstance(sig, FunctionLike):

mypy/server/update.py

-7
Original file line numberDiff line numberDiff line change
@@ -485,13 +485,6 @@ def ensure_trees_loaded(manager: BuildManager, graph: Dict[str, State],
485485
process_fresh_modules(graph, to_process, manager)
486486

487487

488-
def fix_fg_dependencies(manager: BuildManager, deps: Dict[str, Set[str]]) -> None:
489-
"""Populate the dependencies with stuff that build may have missed"""
490-
# This means the root module and typestate
491-
merge_dependencies(manager.load_fine_grained_deps(FAKE_ROOT_MODULE), deps)
492-
# TypeState.add_all_protocol_deps(deps)
493-
494-
495488
# The result of update_module_isolated when no blockers, with these items:
496489
#
497490
# - Id of the changed module (can be different from the module argument)

mypy/subtypes.py

-4
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,6 @@ def _is_subtype(left: Type, right: Type,
154154
ignore_promotions=ignore_promotions))
155155

156156

157-
def is_subtype_ignoring_tvars(left: Type, right: Type) -> bool:
158-
return is_subtype(left, right, ignore_type_params=True)
159-
160-
161157
def is_equivalent(a: Type, b: Type,
162158
*,
163159
ignore_type_params: bool = False,

mypy/suggestions.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,11 @@ def get_args(self, is_method: bool,
344344
types.append(arg_types)
345345
return types
346346

347-
def get_default_arg_types(self, state: State, fdef: FuncDef) -> List[Optional[Type]]:
348-
return [self.manager.all_types[arg.initializer] if arg.initializer else None
349-
for arg in fdef.arguments]
347+
def get_default_arg_types(self, fdef: FuncDef) -> List[Optional[Type]]:
348+
return [
349+
self.manager.all_types[arg.initializer] if arg.initializer else None
350+
for arg in fdef.arguments
351+
]
350352

351353
def add_adjustments(self, typs: List[Type]) -> List[Type]:
352354
if not self.try_text or self.manager.options.python_version[0] != 2:
@@ -441,7 +443,7 @@ def get_suggestion(self, mod: str, node: FuncDef) -> PyAnnotateSignature:
441443
guesses = self.get_guesses(
442444
is_method,
443445
self.get_starting_type(node),
444-
self.get_default_arg_types(graph[mod], node),
446+
self.get_default_arg_types(node),
445447
callsites,
446448
uses,
447449
)
@@ -632,11 +634,8 @@ def try_type(self, func: FuncDef, typ: ProperType) -> List[str]:
632634
finally:
633635
func.unanalyzed_type = old
634636

635-
def reload(self, state: State, check_errors: bool = False) -> List[str]:
636-
"""Recheck the module given by state.
637-
638-
If check_errors is true, raise an exception if there are errors.
639-
"""
637+
def reload(self, state: State) -> List[str]:
638+
"""Recheck the module given by state."""
640639
assert state.path is not None
641640
self.fgmanager.flush_cache()
642641
return self.fgmanager.update([(state.id, state.path)], [])

mypy/typeanal.py

-20
Original file line numberDiff line numberDiff line change
@@ -1358,26 +1358,6 @@ def visit_typeddict_type(self, t: TypedDictType) -> bool:
13581358
return False
13591359

13601360

1361-
def collect_any_types(t: Type) -> List[AnyType]:
1362-
"""Return all inner `AnyType`s of type t"""
1363-
return t.accept(CollectAnyTypesQuery())
1364-
1365-
1366-
class CollectAnyTypesQuery(TypeQuery[List[AnyType]]):
1367-
def __init__(self) -> None:
1368-
super().__init__(self.combine_lists_strategy)
1369-
1370-
def visit_any(self, t: AnyType) -> List[AnyType]:
1371-
return [t]
1372-
1373-
@classmethod
1374-
def combine_lists_strategy(cls, it: Iterable[List[AnyType]]) -> List[AnyType]:
1375-
result: List[AnyType] = []
1376-
for l in it:
1377-
result.extend(l)
1378-
return result
1379-
1380-
13811361
def collect_all_inner_types(t: Type) -> List[Type]:
13821362
"""
13831363
Return all types that `t` contains

mypy/typeops.py

+1-20
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from mypy.types import (
1414
TupleType, Instance, FunctionLike, Type, CallableType, TypeVarLikeType, Overloaded,
15-
TypeVarType, UninhabitedType, FormalArgument, UnionType, NoneType, TypedDictType,
15+
TypeVarType, UninhabitedType, FormalArgument, UnionType, NoneType,
1616
AnyType, TypeOfAny, TypeType, ProperType, LiteralType, get_proper_type, get_proper_types,
1717
copy_type, TypeAliasType, TypeQuery, ParamSpecType
1818
)
@@ -44,25 +44,6 @@ def tuple_fallback(typ: TupleType) -> Instance:
4444
return Instance(info, [join_type_list(typ.items)])
4545

4646

47-
def try_getting_instance_fallback(typ: ProperType) -> Optional[Instance]:
48-
"""Returns the Instance fallback for this type if one exists.
49-
50-
Otherwise, returns None.
51-
"""
52-
if isinstance(typ, Instance):
53-
return typ
54-
elif isinstance(typ, TupleType):
55-
return tuple_fallback(typ)
56-
elif isinstance(typ, TypedDictType):
57-
return typ.fallback
58-
elif isinstance(typ, FunctionLike):
59-
return typ.fallback
60-
elif isinstance(typ, LiteralType):
61-
return typ.fallback
62-
else:
63-
return None
64-
65-
6647
def type_object_type_from_function(signature: FunctionLike,
6748
info: TypeInfo,
6849
def_info: TypeInfo,

mypy/types.py

+28-2
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,31 @@ class Instance(ProperType):
903903
"""An instance type of form C[T1, ..., Tn].
904904
905905
The list of type variables may be empty.
906+
907+
Several types has fallbacks to `Instance`. Why?
908+
Because, for example `TupleTuple` is related to `builtins.tuple` instance.
909+
And `FunctionLike` has `builtins.function` fallback.
910+
This allows us to use types defined
911+
in typeshed for our "special" and more precise types.
912+
913+
We used to have this helper function to get a fallback from different types.
914+
Note, that it might be incomplete, since it is not used and not updated.
915+
It just illustrates the concept:
916+
917+
def try_getting_instance_fallback(typ: ProperType) -> Optional[Instance]:
918+
'''Returns the Instance fallback for this type if one exists or None.'''
919+
if isinstance(typ, Instance):
920+
return typ
921+
elif isinstance(typ, TupleType):
922+
return tuple_fallback(typ)
923+
elif isinstance(typ, TypedDictType):
924+
return typ.fallback
925+
elif isinstance(typ, FunctionLike):
926+
return typ.fallback
927+
elif isinstance(typ, LiteralType):
928+
return typ.fallback
929+
return None
930+
906931
"""
907932

908933
__slots__ = ('type', 'args', 'erased', 'invalid', 'type_ref', 'last_known_value')
@@ -1033,10 +1058,11 @@ class FunctionLike(ProperType):
10331058

10341059
__slots__ = ('fallback',)
10351060

1061+
fallback: Instance
1062+
10361063
def __init__(self, line: int = -1, column: int = -1) -> None:
10371064
super().__init__(line, column)
10381065
self.can_be_false = False
1039-
self.fallback: Instance
10401066

10411067
@abstractmethod
10421068
def is_type_obj(self) -> bool: pass
@@ -1639,7 +1665,7 @@ def copy_modified(self, *, fallback: Optional[Instance] = None,
16391665
required_keys = self.required_keys
16401666
return TypedDictType(items, required_keys, fallback, self.line, self.column)
16411667

1642-
def create_anonymous_fallback(self, *, value_type: Type) -> Instance:
1668+
def create_anonymous_fallback(self) -> Instance:
16431669
anonymous = self.as_anonymous()
16441670
return anonymous.fallback
16451671

0 commit comments

Comments
 (0)