Skip to content

Commit e212c38

Browse files
committed
Eliminate implicit reexports
This makes mypy check clean with the proposed --no-implicit-reexports flag from PR #6562. Some of the implicit reexports that were depended on were clearly intended (type_visitor) and so made explicit, while some were clearly unintended (Optional from mypy.types!) and fixed. Probably worth landing this whichever way we decide on #6562, but I think this PR is an argument in favor.
1 parent bcd0480 commit e212c38

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

mypy/checker.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
ComparisonExpr, StarExpr, EllipsisExpr, RefExpr, PromoteExpr,
2323
Import, ImportFrom, ImportAll, ImportBase, TypeAlias,
2424
ARG_POS, ARG_STAR, LITERAL_TYPE, MDEF, GDEF,
25-
CONTRAVARIANT, COVARIANT, INVARIANT, TypeVarExpr
25+
CONTRAVARIANT, COVARIANT, INVARIANT, TypeVarExpr,
26+
is_final_node,
2627
)
2728
from mypy import nodes
2829
from mypy.literals import literal, literal_hash
@@ -39,7 +40,7 @@
3940
import mypy.checkexpr
4041
from mypy.checkmember import (
4142
map_type_from_supertype, bind_self, erase_to_bound, type_object_type,
42-
analyze_descriptor_access, is_final_node
43+
analyze_descriptor_access,
4344
)
4445
from mypy import message_registry
4546
from mypy.subtypes import (

mypy/exprtotype.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
"""Translate an Expression to a Type value."""
22

3+
from typing import Optional
4+
35
from mypy.nodes import (
46
Expression, NameExpr, MemberExpr, IndexExpr, TupleExpr, IntExpr, FloatExpr, UnaryExpr,
57
ComplexExpr, ListExpr, StrExpr, BytesExpr, UnicodeExpr, EllipsisExpr, CallExpr,
68
get_member_expr_fullname
79
)
810
from mypy.fastparse import parse_type_string
911
from mypy.types import (
10-
Type, UnboundType, TypeList, EllipsisType, AnyType, Optional, CallableArgument, TypeOfAny,
12+
Type, UnboundType, TypeList, EllipsisType, AnyType, CallableArgument, TypeOfAny,
1113
RawExpressionType,
1214
)
1315

mypy/semanal.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@
8484
DynamicClassDefContext
8585
)
8686
from mypy.util import get_prefix, correct_relative_import, unmangle
87-
from mypy.semanal_shared import SemanticAnalyzerInterface, set_callable_name
87+
from mypy.semanal_shared import (
88+
SemanticAnalyzerInterface,
89+
set_callable_name as set_callable_name,
90+
)
8891
from mypy.scope import Scope
8992
from mypy.semanal_namedtuple import NamedTupleAnalyzer, NAMEDTUPLE_PROHIBITED_NAMES
9093
from mypy.semanal_typeddict import TypedDictAnalyzer

mypy/test/teststubgen.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
from mypy.test.data import DataSuite, DataDrivenTestCase
1313
from mypy.errors import CompileError
1414
from mypy.stubgen import (
15-
generate_stubs, parse_options, walk_packages, Options, collect_build_targets,
15+
generate_stubs, parse_options, Options, collect_build_targets,
1616
mypy_options
1717
)
18+
from mypy.stubutil import walk_packages
1819
from mypy.stubgenc import generate_c_type_stub, infer_method_sig, generate_c_function_stub
1920
from mypy.stubdoc import (
2021
parse_signature, parse_all_signatures, build_signature, find_unique_signatures,

mypy/types.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,13 @@
6161
# breaks, and if we do it at the top, it breaks at runtime because of
6262
# import cycle issues, so we do it at the top while typechecking and
6363
# then again in the middle at runtime.
64+
# We should be able to remove this once we are switched to the new
65+
# semantic analyzer!
6466
if MYPY:
65-
from mypy.type_visitor import TypeVisitor, SyntheticTypeVisitor
67+
from mypy.type_visitor import (
68+
TypeVisitor as TypeVisitor,
69+
SyntheticTypeVisitor as SyntheticTypeVisitor,
70+
)
6671

6772

6873
class TypeOfAny:
@@ -1832,7 +1837,10 @@ def serialize(self) -> str:
18321837
# Import them here, after the types are defined.
18331838
# This is intended as a re-export also.
18341839
from mypy.type_visitor import ( # noqa
1835-
TypeVisitor, SyntheticTypeVisitor, TypeTranslator, TypeQuery
1840+
TypeVisitor as TypeVisitor,
1841+
SyntheticTypeVisitor as SyntheticTypeVisitor,
1842+
TypeTranslator as TypeTranslator,
1843+
TypeQuery as TypeQuery,
18361844
)
18371845

18381846

0 commit comments

Comments
 (0)