Skip to content

Commit 3801bcc

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent bd5911f commit 3801bcc

File tree

4 files changed

+30
-26
lines changed

4 files changed

+30
-26
lines changed

mypy/checker.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2560,9 +2560,11 @@ def visit_class_def(self, defn: ClassDef) -> None:
25602560
for base in typ.mro[1:]:
25612561
if base.is_final:
25622562
self.fail(message_registry.CANNOT_INHERIT_FROM_FINAL.format(base.name), defn)
2563-
with self.tscope.class_scope(defn.info), \
2564-
self.enter_partial_types(is_class=True), \
2565-
self.enter_class(defn.info):
2563+
with (
2564+
self.tscope.class_scope(defn.info),
2565+
self.enter_partial_types(is_class=True),
2566+
self.enter_class(defn.info),
2567+
):
25662568
old_binder = self.binder
25672569
self.binder = ConditionalTypeBinder()
25682570
with self.binder.top_frame_context():
@@ -7946,6 +7948,7 @@ class TypeCheckerAsSemanticAnalyzer(SemanticAnalyzerCoreInterface):
79467948
See ExpressionChecker.try_parse_as_type_expression() to understand how this
79477949
class is used.
79487950
"""
7951+
79497952
_chk: TypeChecker
79507953
_names: dict[str, SymbolTableNode]
79517954
did_fail: bool
@@ -7991,7 +7994,7 @@ def note(self, msg: str, ctx: Context, *, code: ErrorCode | None = None) -> None
79917994

79927995
def incomplete_feature_enabled(self, feature: str, ctx: Context) -> bool:
79937996
if feature not in self._chk.options.enable_incomplete_feature:
7994-
self.fail('__ignored__', ctx)
7997+
self.fail("__ignored__", ctx)
79957998
return False
79967999
return True
79978000

mypy/checkexpr.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
freshen_all_functions_type_vars,
3131
freshen_function_type_vars,
3232
)
33-
from mypy.exprtotype import expr_to_unanalyzed_type, TypeTranslationError
33+
from mypy.exprtotype import TypeTranslationError, expr_to_unanalyzed_type
3434
from mypy.infer import ArgumentInferContext, infer_function_type_arguments, infer_type_arguments
3535
from mypy.literals import literal
3636
from mypy.maptype import map_instance_to_supertype
@@ -47,6 +47,7 @@
4747
LITERAL_TYPE,
4848
REVEAL_LOCALS,
4949
REVEAL_TYPE,
50+
UNBOUND_IMPORTED,
5051
ArgKind,
5152
AssertTypeExpr,
5253
AssignmentExpr,
@@ -67,7 +68,6 @@
6768
FloatExpr,
6869
FuncDef,
6970
GeneratorExpr,
70-
get_member_expr_fullname,
7171
IndexExpr,
7272
IntExpr,
7373
LambdaExpr,
@@ -105,10 +105,10 @@
105105
TypeVarExpr,
106106
TypeVarTupleExpr,
107107
UnaryExpr,
108-
UNBOUND_IMPORTED,
109108
Var,
110109
YieldExpr,
111110
YieldFromExpr,
111+
get_member_expr_fullname,
112112
)
113113
from mypy.options import PRECISE_TUPLE_TYPES
114114
from mypy.plugin import (
@@ -127,16 +127,20 @@
127127
is_subtype,
128128
non_method_protocol_members,
129129
)
130-
from mypy.traverser import all_name_and_member_expressions, has_await_expression, has_str_expression
130+
from mypy.traverser import (
131+
all_name_and_member_expressions,
132+
has_await_expression,
133+
has_str_expression,
134+
)
131135
from mypy.tvar_scope import TypeVarLikeScope
132136
from mypy.typeanal import (
137+
TypeAnalyser,
133138
check_for_explicit_any,
134139
fix_instance,
135140
has_any_from_unimported_type,
136141
instantiate_type_alias,
137142
make_optional_type,
138143
set_any_tvars,
139-
TypeAnalyser,
140144
validate_instance,
141145
)
142146
from mypy.typeops import (
@@ -6335,17 +6339,19 @@ def try_parse_as_type_expression(self, maybe_type_expr: Expression) -> Type | No
63356339
# Check whether has already been parsed as a type expression
63366340
# by SemanticAnalyzer.try_parse_as_type_expression(),
63376341
# perhaps containing a string annotation
6338-
if (isinstance(maybe_type_expr, (StrExpr, IndexExpr, OpExpr))
6339-
and maybe_type_expr.as_type is not Ellipsis):
6342+
if (
6343+
isinstance(maybe_type_expr, (StrExpr, IndexExpr, OpExpr))
6344+
and maybe_type_expr.as_type is not Ellipsis
6345+
):
63406346
return maybe_type_expr.as_type
63416347

63426348
# If is potentially a type expression containing a string annotation,
63436349
# don't try to parse it because there isn't enough information
63446350
# available to the TypeChecker pass to resolve string annotations
63456351
if has_str_expression(maybe_type_expr):
63466352
self.chk.note(
6347-
'TypeForm containing a string annotation cannot be recognized here. '
6348-
'Try assigning the TypeForm to a variable and use the variable here instead.',
6353+
"TypeForm containing a string annotation cannot be recognized here. "
6354+
"Try assigning the TypeForm to a variable and use the variable here instead.",
63496355
maybe_type_expr,
63506356
)
63516357
return None
@@ -6354,13 +6360,8 @@ def try_parse_as_type_expression(self, maybe_type_expr: Expression) -> Type | No
63546360
# to be looked up by TypeAnalyser when binding the
63556361
# UnboundTypes corresponding to those expressions.
63566362
(name_exprs, member_exprs) = all_name_and_member_expressions(maybe_type_expr)
6357-
sym_for_name = {
6358-
e.name:
6359-
SymbolTableNode(UNBOUND_IMPORTED, e.node)
6360-
for e in name_exprs
6361-
} | {
6362-
e_name:
6363-
SymbolTableNode(UNBOUND_IMPORTED, e.node)
6363+
sym_for_name = {e.name: SymbolTableNode(UNBOUND_IMPORTED, e.node) for e in name_exprs} | {
6364+
e_name: SymbolTableNode(UNBOUND_IMPORTED, e.node)
63646365
for e in member_exprs
63656366
if (e_name := get_member_expr_fullname(e)) is not None
63666367
}
@@ -6377,7 +6378,7 @@ def try_parse_as_type_expression(self, maybe_type_expr: Expression) -> Type | No
63776378

63786379
try:
63796380
typ1 = expr_to_unanalyzed_type(
6380-
maybe_type_expr, self.chk.options, self.chk.is_typeshed_stub,
6381+
maybe_type_expr, self.chk.options, self.chk.is_typeshed_stub
63816382
)
63826383
typ2 = typ1.accept(tpan)
63836384
if chk_sem.did_fail:

mypy/nodes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
from __future__ import annotations
44

5+
import builtins
56
import os
67
from abc import abstractmethod
7-
import builtins
88
from collections import defaultdict
99
from collections.abc import Iterator, Sequence
1010
from enum import Enum, unique
@@ -25,6 +25,7 @@
2525
else:
2626
EllipsisType = Any
2727

28+
2829
class Context:
2930
"""Base type for objects that are valid as error message locations."""
3031

mypy/semanal.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@
5050

5151
from __future__ import annotations
5252

53+
import re
5354
from collections.abc import Collection, Iterable, Iterator
5455
from contextlib import contextmanager
5556
from typing import Any, Callable, Final, TypeVar, cast
56-
from typing_extensions import TypeAlias as _TypeAlias, TypeGuard
57+
from typing_extensions import TypeAlias as _TypeAlias, TypeGuard, assert_never
5758

5859
from mypy import errorcodes as codes, message_registry
5960
from mypy.constant_fold import constant_fold_expr
@@ -308,8 +309,6 @@
308309
from mypy.typevars import fill_typevars
309310
from mypy.util import correct_relative_import, is_dunder, module_prefix, unmangle, unnamed_function
310311
from mypy.visitor import NodeVisitor
311-
import re
312-
from typing_extensions import assert_never
313312

314313
T = TypeVar("T")
315314

@@ -7695,7 +7694,7 @@ def try_parse_as_type_expression(self, maybe_type_expr: Expression) -> None:
76957694
maybe_type_expr.as_type = None
76967695
return
76977696
elif isinstance(maybe_type_expr, OpExpr):
7698-
if maybe_type_expr.op != '|':
7697+
if maybe_type_expr.op != "|":
76997698
# Binary operators other than '|' never spell a valid type
77007699
maybe_type_expr.as_type = None
77017700
return

0 commit comments

Comments
 (0)