Skip to content

Commit 2e9c9b4

Browse files
authored
Solve import cycles in expandtype and testtypes.py (#15580)
1 parent 4df2215 commit 2e9c9b4

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

mypy/expandtype.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from mypy.nodes import ARG_POS, ARG_STAR, ArgKind, Var
77
from mypy.state import state
8-
from mypy.type_visitor import TypeTranslator
98
from mypy.types import (
109
ANY_STRATEGY,
1110
AnyType,
@@ -44,6 +43,9 @@
4443
)
4544
from mypy.typevartuples import find_unpack_in_list, split_with_instance
4645

46+
# Solving the import cycle:
47+
import mypy.type_visitor # ruff: isort: skip
48+
4749
# WARNING: these functions should never (directly or indirectly) depend on
4850
# is_subtype(), meet_types(), join_types() etc.
4951
# TODO: add a static dependency test for this.
@@ -167,7 +169,7 @@ def freshen_all_functions_type_vars(t: T) -> T:
167169
return result
168170

169171

170-
class FreshenCallableVisitor(TypeTranslator):
172+
class FreshenCallableVisitor(mypy.type_visitor.TypeTranslator):
171173
def visit_callable_type(self, t: CallableType) -> Type:
172174
result = super().visit_callable_type(t)
173175
assert isinstance(result, ProperType) and isinstance(result, CallableType)

mypy/test/testtypes.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
import re
66
from unittest import TestCase, skipUnless
77

8-
import mypy.expandtype
98
from mypy.erasetype import erase_type, remove_instance_last_known_values
10-
from mypy.expandtype import expand_type
119
from mypy.indirection import TypeIndirectionVisitor
1210
from mypy.join import join_simple, join_types
1311
from mypy.meet import meet_types, narrow_declared_type
@@ -53,6 +51,9 @@
5351
has_recursive_types,
5452
)
5553

54+
# Solving the import cycle:
55+
import mypy.expandtype # ruff: isort: skip
56+
5657

5758
class TypesSuite(Suite):
5859
def setUp(self) -> None:
@@ -268,7 +269,7 @@ def assert_expand(
268269
for id, t in map_items:
269270
lower_bounds[id] = t
270271

271-
exp = expand_type(orig, lower_bounds)
272+
exp = mypy.expandtype.expand_type(orig, lower_bounds)
272273
# Remove erased tags (asterisks).
273274
assert_equal(str(exp).replace("*", ""), str(result))
274275

0 commit comments

Comments
 (0)