Skip to content

Commit 50706fd

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

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

mypy/checkexpr.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -482,23 +482,21 @@ def visit_call_expr(self, e: CallExpr, allow_none_return: bool = False) -> Type:
482482
if isinstance(typeddict_callable, CallableType):
483483
typeddict_type = get_proper_type(typeddict_callable.ret_type)
484484
assert isinstance(typeddict_type, TypedDictType)
485-
return self.check_typeddict_call(
486-
e, typeddict_type, typeddict_callable
487-
)
488-
485+
return self.check_typeddict_call(e, typeddict_type, typeddict_callable)
486+
489487
# Add logic to handle the `get` method
490-
if isinstance(e.callee, MemberExpr) and e.callee.name == 'get':
488+
if isinstance(e.callee, MemberExpr) and e.callee.name == "get":
491489
dict_type = self.accept(e.callee.expr)
492-
if isinstance(dict_type, Instance) and dict_type.type.fullname == 'builtins.dict':
490+
if isinstance(dict_type, Instance) and dict_type.type.fullname == "builtins.dict":
493491
key_type = self.accept(e.args[0])
494492
if len(e.args) == 2:
495493
default_type = self.accept(e.args[1])
496494
return UnionType.make_union([dict_type.args[1], default_type])
497495
return UnionType.make_union([dict_type.args[1], NoneType()])
498-
elif isinstance(dict_type, Instance) and dict_type.type.fullname == 'builtins.dict':
496+
elif isinstance(dict_type, Instance) and dict_type.type.fullname == "builtins.dict":
499497
# Handle empty dictionary case
500498
return AnyType(TypeOfAny.special_form)
501-
499+
502500
if e.analyzed:
503501
if isinstance(e.analyzed, NamedTupleExpr) and not e.analyzed.is_typed:
504502
# Type check the arguments, but ignore the results. This relies

mypy/checkmember.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
from typing import TYPE_CHECKING, Callable, Sequence, cast
6-
from mypy.nodes import ARG_POS, ARG_OPT
6+
77
from mypy import meet, message_registry, subtypes
88
from mypy.erasetype import erase_typevars
99
from mypy.expandtype import (
@@ -14,6 +14,7 @@
1414
from mypy.maptype import map_instance_to_supertype
1515
from mypy.messages import MessageBuilder
1616
from mypy.nodes import (
17+
ARG_OPT,
1718
ARG_POS,
1819
ARG_STAR,
1920
ARG_STAR2,
@@ -203,11 +204,11 @@ def analyze_member_access(
203204
no_deferral=no_deferral,
204205
is_self=is_self,
205206
)
206-
207-
if name == 'get' and isinstance(typ, Instance) and typ.type.fullname == 'builtins.dict':
207+
208+
if name == "get" and isinstance(typ, Instance) and typ.type.fullname == "builtins.dict":
208209
# Handle overload resolution for dict.get
209210
return analyze_dict_get(typ, context)
210-
211+
211212
result = _analyze_member_access(name, typ, mx, override_info)
212213
possible_literal = get_proper_type(result)
213214
if (
@@ -219,6 +220,7 @@ def analyze_member_access(
219220
else:
220221
return result
221222

223+
222224
def analyze_dict_get(self, typ: Instance, context: Context) -> Type:
223225
key_type = typ.args[0]
224226
value_type = typ.args[1]
@@ -227,9 +229,10 @@ def analyze_dict_get(self, typ: Instance, context: Context) -> Type:
227229
[ARG_POS, ARG_OPT],
228230
[None, None],
229231
UnionType.make_union([value_type, NoneType()]),
230-
self.named_type('builtins.function')
232+
self.named_type("builtins.function"),
231233
)
232-
234+
235+
233236
def _analyze_member_access(
234237
name: str, typ: Type, mx: MemberContext, override_info: TypeInfo | None = None
235238
) -> Type:

test-data/unit/check-dict-get.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ def testDictGetExistingKey() -> None:
1616
[case testDictGetMissingKey]
1717
def testDictGetMissingKey() -> None:
1818
x = {"a": 1}.get("b")
19-
reveal_type(x) # N: Revealed type is "None"
19+
reveal_type(x) # N: Revealed type is "None"

0 commit comments

Comments
 (0)