Skip to content

Commit 9dcfc23

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

File tree

9 files changed

+38
-32
lines changed

9 files changed

+38
-32
lines changed

mypy/checker.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7787,8 +7787,7 @@ def add_any_attribute_to_type(self, typ: Type, name: str) -> Type:
77877787
return typ.copy_modified(fallback=fallback)
77887788
if isinstance(typ, TypeType) and isinstance(typ.item, Instance):
77897789
return TypeType.make_normalized(
7790-
self.add_any_attribute_to_type(typ.item, name),
7791-
is_type_form=typ.is_type_form,
7790+
self.add_any_attribute_to_type(typ.item, name), is_type_form=typ.is_type_form
77927791
)
77937792
if isinstance(typ, TypeVarType):
77947793
return typ.copy_modified(

mypy/checkexpr.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5947,9 +5947,9 @@ def accept(
59475947
elif allow_none_return and isinstance(node, AwaitExpr):
59485948
typ = self.visit_await_expr(node, allow_none_return=True)
59495949
elif (
5950-
isinstance(p_type_context, TypeType) and
5951-
p_type_context.is_type_form and
5952-
node.as_type is not None
5950+
isinstance(p_type_context, TypeType)
5951+
and p_type_context.is_type_form
5952+
and node.as_type is not None
59535953
):
59545954
typ = TypeType.make_normalized(
59555955
node.as_type,

mypy/erasetype.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ def visit_union_type(self, t: UnionType) -> ProperType:
134134
return make_simplified_union(erased_items)
135135

136136
def visit_type_type(self, t: TypeType) -> ProperType:
137-
return TypeType.make_normalized(t.item.accept(self), line=t.line, is_type_form=t.is_type_form)
137+
return TypeType.make_normalized(
138+
t.item.accept(self), line=t.line, is_type_form=t.is_type_form
139+
)
138140

139141
def visit_type_alias_type(self, t: TypeAliasType) -> ProperType:
140142
raise RuntimeError("Type aliases should be expanded before accepting this visitor")

mypy/meet.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,7 @@ def narrow_declared_type(declared: Type, narrowed: Type) -> Type:
172172
# type object at least as narrow as Type[T]
173173
return narrow_declared_type(
174174
TypeType.make_normalized(
175-
declared.item,
176-
line=declared.line,
177-
column=declared.column,
178-
is_type_form=False,
175+
declared.item, line=declared.line, column=declared.column, is_type_form=False
179176
),
180177
original_narrowed,
181178
)
@@ -1090,9 +1087,7 @@ def visit_type_type(self, t: TypeType) -> ProperType:
10901087
typ = self.meet(t.item, self.s.item)
10911088
if not isinstance(typ, NoneType):
10921089
typ = TypeType.make_normalized(
1093-
typ,
1094-
line=t.line,
1095-
is_type_form=self.s.is_type_form and t.is_type_form,
1090+
typ, line=t.line, is_type_form=self.s.is_type_form and t.is_type_form
10961091
)
10971092
return typ
10981093
elif isinstance(self.s, Instance) and self.s.type.fullname == "builtins.type":

mypy/nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class Expression(Node):
205205
# a different superclass with its own __slots__. A subclass in
206206
# Python is not allowed to have multiple superclasses that define
207207
# __slots__.
208-
#__slots__ = ('as_type',)
208+
# __slots__ = ('as_type',)
209209

210210
# If this value expression can also be parsed as a valid type expression,
211211
# represents the type denoted by the type expression.

mypy/semanal.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
type_aliases_source_versions,
193193
typing_extensions_aliases,
194194
)
195-
from mypy.options import Options, TYPE_FORM
195+
from mypy.options import TYPE_FORM, Options
196196
from mypy.patterns import (
197197
AsPattern,
198198
ClassPattern,
@@ -5799,9 +5799,7 @@ def visit_call_expr(self, expr: CallExpr) -> None:
57995799
with self.allow_unbound_tvars_set():
58005800
for a in expr.args:
58015801
a.accept(self)
5802-
elif refers_to_fullname(
5803-
expr.callee, ("typing.TypeForm", "typing_extensions.TypeForm")
5804-
):
5802+
elif refers_to_fullname(expr.callee, ("typing.TypeForm", "typing_extensions.TypeForm")):
58055803
# Special form TypeForm(...).
58065804
if not self.check_fixed_args(expr, 1, "TypeForm"):
58075805
return
@@ -7620,15 +7618,19 @@ def visit_pass_stmt(self, o: PassStmt, /) -> None:
76207618
def visit_singleton_pattern(self, o: SingletonPattern, /) -> None:
76217619
return None
76227620

7623-
def try_parse_as_type_expression(self, maybe_type_expr: Expression) -> Type|None:
7621+
def try_parse_as_type_expression(self, maybe_type_expr: Expression) -> Type | None:
76247622
"""Try to parse maybe_type_expr as a type expression.
76257623
If parsing fails return None and emit no errors."""
76267624
# Save SemanticAnalyzer state
76277625
original_errors = self.errors # altered by fail()
7628-
original_num_incomplete_refs = self.num_incomplete_refs # altered by record_incomplete_ref()
7626+
original_num_incomplete_refs = (
7627+
self.num_incomplete_refs
7628+
) # altered by record_incomplete_ref()
76297629
original_progress = self.progress # altered by defer()
76307630
original_deferred = self.deferred # altered by defer()
7631-
original_deferral_debug_context_len = len(self.deferral_debug_context) # altered by defer()
7631+
original_deferral_debug_context_len = len(
7632+
self.deferral_debug_context
7633+
) # altered by defer()
76327634

76337635
self.errors = Errors(Options())
76347636
try:
@@ -7649,6 +7651,7 @@ def try_parse_as_type_expression(self, maybe_type_expr: Expression) -> Type|None
76497651
del self.deferral_debug_context[original_deferral_debug_context_len:]
76507652
return t
76517653

7654+
76527655
def replace_implicit_first_type(sig: FunctionLike, new: Type) -> FunctionLike:
76537656
if isinstance(sig, CallableType):
76547657
if len(sig.arg_types) == 0:

mypy/type_visitor.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,7 @@ def visit_overloaded(self, t: Overloaded, /) -> Type:
326326

327327
def visit_type_type(self, t: TypeType, /) -> Type:
328328
return TypeType.make_normalized(
329-
t.item.accept(self),
330-
line=t.line,
331-
column=t.column,
332-
is_type_form=t.is_type_form,
329+
t.item.accept(self), line=t.line, column=t.column, is_type_form=t.is_type_form
333330
)
334331

335332
@abstractmethod

mypy/typeanal.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
check_arg_names,
5050
get_nongen_builtins,
5151
)
52-
from mypy.options import INLINE_TYPEDDICT, Options, TYPE_FORM
52+
from mypy.options import INLINE_TYPEDDICT, TYPE_FORM, Options
5353
from mypy.plugin import AnalyzeTypeContext, Plugin, TypeAnalyzerPluginInterface
5454
from mypy.semanal_shared import (
5555
SemanticAnalyzerCoreInterface,
@@ -1363,7 +1363,7 @@ def visit_typeddict_type(self, t: TypedDictType) -> Type:
13631363
try:
13641364
fallback = self.named_type("typing._TypedDict")
13651365
except AssertionError as e:
1366-
if str(e) == 'typing._TypedDict':
1366+
if str(e) == "typing._TypedDict":
13671367
# Can happen when running mypy tests, typing._TypedDict
13681368
# is not defined by typing.pyi stubs, and
13691369
# try_parse_as_type_expression() is called on an dict
@@ -1453,7 +1453,9 @@ def visit_ellipsis_type(self, t: EllipsisType) -> Type:
14531453
return AnyType(TypeOfAny.from_error)
14541454

14551455
def visit_type_type(self, t: TypeType) -> Type:
1456-
return TypeType.make_normalized(self.anal_type(t.item), line=t.line, is_type_form=t.is_type_form)
1456+
return TypeType.make_normalized(
1457+
self.anal_type(t.item), line=t.line, is_type_form=t.is_type_form
1458+
)
14571459

14581460
def visit_placeholder_type(self, t: PlaceholderType) -> Type:
14591461
n = (

mypy/types.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3089,7 +3089,7 @@ class TypeType(ProperType):
30893089
assumption).
30903090
"""
30913091

3092-
__slots__ = ("item", "is_type_form",)
3092+
__slots__ = ("item", "is_type_form")
30933093

30943094
# This can't be everything, but it can be a class reference,
30953095
# a generic class instance, a union, Any, a type variable...
@@ -3115,7 +3115,9 @@ def __init__(
31153115
self.is_type_form = is_type_form
31163116

31173117
@staticmethod
3118-
def make_normalized(item: Type, *, line: int = -1, column: int = -1, is_type_form: bool = False) -> ProperType:
3118+
def make_normalized(
3119+
item: Type, *, line: int = -1, column: int = -1, is_type_form: bool = False
3120+
) -> ProperType:
31193121
item = get_proper_type(item)
31203122
if is_type_form:
31213123
# Don't convert TypeForm[X | Y] to (TypeForm[X] | TypeForm[Y])
@@ -3141,12 +3143,18 @@ def __eq__(self, other: object) -> bool:
31413143
return self.item == other.item
31423144

31433145
def serialize(self) -> JsonDict:
3144-
return {".class": "TypeType", "item": self.item.serialize(), "is_type_form": self.is_type_form}
3146+
return {
3147+
".class": "TypeType",
3148+
"item": self.item.serialize(),
3149+
"is_type_form": self.is_type_form,
3150+
}
31453151

31463152
@classmethod
31473153
def deserialize(cls, data: JsonDict) -> Type:
31483154
assert data[".class"] == "TypeType"
3149-
return TypeType.make_normalized(deserialize_type(data["item"]), is_type_form=data["is_type_form"])
3155+
return TypeType.make_normalized(
3156+
deserialize_type(data["item"]), is_type_form=data["is_type_form"]
3157+
)
31503158

31513159

31523160
class PlaceholderType(ProperType):

0 commit comments

Comments
 (0)