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

Skip to content

Delete sametypes.py #13311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions mypy/applytype.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Callable, Dict, Optional, Sequence

import mypy.sametypes
import mypy.subtypes
from mypy.expandtype import expand_type
from mypy.nodes import Context
Expand Down Expand Up @@ -41,7 +40,7 @@ def get_target_type(
if isinstance(type, TypeVarType) and type.values:
# Allow substituting T1 for T if every allowed value of T1
# is also a legal value of T.
if all(any(mypy.sametypes.is_same_type(v, v1) for v in values) for v1 in type.values):
if all(any(mypy.subtypes.is_same_type(v, v1) for v in values) for v1 in type.values):
return type
matching = []
for value in values:
Expand Down
3 changes: 1 addition & 2 deletions mypy/binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from mypy.join import join_simple
from mypy.literals import Key, literal, literal_hash, subkeys
from mypy.nodes import AssignmentExpr, Expression, IndexExpr, MemberExpr, NameExpr, RefExpr, Var
from mypy.sametypes import is_same_type
from mypy.subtypes import is_subtype
from mypy.subtypes import is_same_type, is_subtype
from mypy.types import AnyType, NoneType, PartialType, Type, TypeOfAny, UnionType, get_proper_type

BindableExpression: _TypeAlias = Union[IndexExpr, MemberExpr, AssignmentExpr, NameExpr]
Expand Down
2 changes: 1 addition & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@
)
from mypy.options import Options
from mypy.plugin import CheckerPluginInterface, Plugin
from mypy.sametypes import is_same_type
from mypy.scope import Scope
from mypy.semanal import is_trivial_body, refers_to_fullname, set_callable_name
from mypy.semanal_enum import ENUM_BASES, ENUM_SPECIAL_PROPS
Expand All @@ -145,6 +144,7 @@
is_equivalent,
is_more_precise,
is_proper_subtype,
is_same_type,
is_subtype,
restrict_subtype_away,
unify_generic_callable,
Expand Down
5 changes: 2 additions & 3 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,9 @@
MethodSigContext,
Plugin,
)
from mypy.sametypes import is_same_type
from mypy.semanal_enum import ENUM_BASES
from mypy.state import state
from mypy.subtypes import is_equivalent, is_subtype, non_method_protocol_members
from mypy.subtypes import is_equivalent, is_same_type, is_subtype, non_method_protocol_members
from mypy.traverser import has_await_expression
from mypy.typeanal import (
check_for_explicit_any,
Expand Down Expand Up @@ -3574,7 +3573,7 @@ def visit_cast_expr(self, expr: CastExpr) -> Type:
if (
options.warn_redundant_casts
and not isinstance(get_proper_type(target_type), AnyType)
and is_same_type(source_type, target_type)
and source_type == target_type
):
self.msg.redundant_cast(target_type, expr)
if options.disallow_any_unimported and has_any_from_unimported_type(target_type):
Expand Down
19 changes: 10 additions & 9 deletions mypy/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

from typing_extensions import Final

import mypy.sametypes
import mypy.subtypes
import mypy.typeops
from mypy.argmap import ArgTypeExpander
from mypy.erasetype import erase_typevars
from mypy.maptype import map_instance_to_supertype
from mypy.nodes import CONTRAVARIANT, COVARIANT, ArgKind
from mypy.nodes import ARG_OPT, ARG_POS, CONTRAVARIANT, COVARIANT, ArgKind
from mypy.types import (
TUPLE_LIKE_INSTANCE_NAMES,
AnyType,
Expand Down Expand Up @@ -141,7 +140,9 @@ def infer_constraints(template: Type, actual: Type, direction: int) -> List[Cons

The constraints are represented as Constraint objects.
"""
if any(get_proper_type(template) == get_proper_type(t) for t in TypeState._inferring):
if any(
get_proper_type(template) == get_proper_type(t) for t in reversed(TypeState._inferring)
):
return []
if isinstance(template, TypeAliasType) and template.is_recursive:
# This case requires special care because it may cause infinite recursion.
Expand Down Expand Up @@ -341,7 +342,7 @@ def is_same_constraint(c1: Constraint, c2: Constraint) -> bool:
return (
c1.type_var == c2.type_var
and (c1.op == c2.op or skip_op_check)
and mypy.sametypes.is_same_type(c1.target, c2.target)
and mypy.subtypes.is_same_type(c1.target, c2.target)
)


Expand Down Expand Up @@ -474,9 +475,7 @@ def visit_instance(self, template: Instance) -> List[Constraint]:
if isinstance(actual, (CallableType, Overloaded)) and template.type.is_protocol:
if template.type.protocol_members == ["__call__"]:
# Special case: a generic callback protocol
if not any(
mypy.sametypes.is_same_type(template, t) for t in template.type.inferring
):
if not any(template == t for t in template.type.inferring):
template.type.inferring.append(template)
call = mypy.subtypes.find_member(
"__call__", template, actual, is_operator=True
Expand Down Expand Up @@ -635,7 +634,7 @@ def visit_instance(self, template: Instance) -> List[Constraint]:
# Note that we use is_protocol_implementation instead of is_subtype
# because some type may be considered a subtype of a protocol
# due to _promote, but still not implement the protocol.
not any(mypy.sametypes.is_same_type(template, t) for t in template.type.inferring)
not any(template == t for t in reversed(template.type.inferring))
and mypy.subtypes.is_protocol_implementation(instance, erased)
):
template.type.inferring.append(template)
Expand All @@ -651,7 +650,7 @@ def visit_instance(self, template: Instance) -> List[Constraint]:
and self.direction == SUBTYPE_OF
and
# We avoid infinite recursion for structural subtypes also here.
not any(mypy.sametypes.is_same_type(instance, i) for i in instance.type.inferring)
not any(instance == i for i in reversed(instance.type.inferring))
and mypy.subtypes.is_protocol_implementation(erased, instance)
):
instance.type.inferring.append(instance)
Expand Down Expand Up @@ -734,6 +733,8 @@ def visit_callable_type(self, template: CallableType) -> List[Constraint]:
cactual_ps = cactual.param_spec()

if not cactual_ps:
max_prefix_len = len([k for k in cactual.arg_kinds if k in (ARG_POS, ARG_OPT)])
prefix_len = min(prefix_len, max_prefix_len)
res.append(
Constraint(
param_spec.id,
Expand Down
2 changes: 1 addition & 1 deletion mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@
reverse_builtin_aliases,
)
from mypy.operators import op_methods, op_methods_to_symbols
from mypy.sametypes import is_same_type
from mypy.subtypes import (
IS_CLASS_OR_STATIC,
IS_CLASSVAR,
IS_SETTABLE,
find_member,
get_member_flags,
is_same_type,
is_subtype,
)
from mypy.typeops import separate_union_literals
Expand Down
245 changes: 0 additions & 245 deletions mypy/sametypes.py

This file was deleted.

Loading