From 2e9c9b4ec9eece1209c6df1e559ed371cdfbd1b3 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Mon, 3 Jul 2023 22:07:10 +0300 Subject: [PATCH] Solve import cycles in expandtype and testtypes.py (#15580) --- mypy/expandtype.py | 6 ++++-- mypy/test/testtypes.py | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/mypy/expandtype.py b/mypy/expandtype.py index 5bbdd5311da7..24835a5ee4d6 100644 --- a/mypy/expandtype.py +++ b/mypy/expandtype.py @@ -5,7 +5,6 @@ from mypy.nodes import ARG_POS, ARG_STAR, ArgKind, Var from mypy.state import state -from mypy.type_visitor import TypeTranslator from mypy.types import ( ANY_STRATEGY, AnyType, @@ -44,6 +43,9 @@ ) from mypy.typevartuples import find_unpack_in_list, split_with_instance +# Solving the import cycle: +import mypy.type_visitor # ruff: isort: skip + # WARNING: these functions should never (directly or indirectly) depend on # is_subtype(), meet_types(), join_types() etc. # TODO: add a static dependency test for this. @@ -167,7 +169,7 @@ def freshen_all_functions_type_vars(t: T) -> T: return result -class FreshenCallableVisitor(TypeTranslator): +class FreshenCallableVisitor(mypy.type_visitor.TypeTranslator): def visit_callable_type(self, t: CallableType) -> Type: result = super().visit_callable_type(t) assert isinstance(result, ProperType) and isinstance(result, CallableType) diff --git a/mypy/test/testtypes.py b/mypy/test/testtypes.py index 246350dc02cd..b1f21b3be79b 100644 --- a/mypy/test/testtypes.py +++ b/mypy/test/testtypes.py @@ -5,9 +5,7 @@ import re from unittest import TestCase, skipUnless -import mypy.expandtype from mypy.erasetype import erase_type, remove_instance_last_known_values -from mypy.expandtype import expand_type from mypy.indirection import TypeIndirectionVisitor from mypy.join import join_simple, join_types from mypy.meet import meet_types, narrow_declared_type @@ -53,6 +51,9 @@ has_recursive_types, ) +# Solving the import cycle: +import mypy.expandtype # ruff: isort: skip + class TypesSuite(Suite): def setUp(self) -> None: @@ -268,7 +269,7 @@ def assert_expand( for id, t in map_items: lower_bounds[id] = t - exp = expand_type(orig, lower_bounds) + exp = mypy.expandtype.expand_type(orig, lower_bounds) # Remove erased tags (asterisks). assert_equal(str(exp).replace("*", ""), str(result))