Skip to content

Commit

Permalink
Solve import cycles for mypy/expandtype.py and `mypy/test/testtypes…
Browse files Browse the repository at this point in the history
….py`
  • Loading branch information
sobolevn committed Jul 3, 2023
1 parent a759c49 commit a7342ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions mypy/expandtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions mypy/test/testtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,6 +51,9 @@
has_recursive_types,
)

# Solving the import cycle:
import mypy.expandtype # ruff: isort: skip


class TypesSuite(Suite):
def setUp(self) -> None:
Expand Down Expand Up @@ -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))

Expand Down

0 comments on commit a7342ca

Please sign in to comment.