Skip to content

Commit dfb1bbe

Browse files
ngnpopeasottile-sentry
authored andcommitted
Fix a crash on mypy master branch (typeddjango#2670)
* Fix a crash on mypy master branch In python/mypy#18818 the `msg` argument to `analyze_member_access()` was removed. * Switch to using a version-based check
1 parent 281be3f commit dfb1bbe

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

mypy_django_plugin/transformers/functional.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
from typing import Any
2+
13
from mypy.checkmember import analyze_member_access
24
from mypy.errorcodes import ATTR_DEFINED
35
from mypy.nodes import CallExpr, MemberExpr
46
from mypy.plugin import AttributeContext
57
from mypy.types import AnyType, Instance, TypeOfAny
68
from mypy.types import Type as MypyType
9+
from mypy.version import __version__ as mypy_version
710

811
from mypy_django_plugin.lib import helpers
912

13+
mypy_version_info = tuple(map(int, mypy_version.partition("+")[0].split(".")))
14+
1015

1116
def resolve_str_promise_attribute(ctx: AttributeContext) -> MypyType:
1217
if isinstance(ctx.context, MemberExpr):
@@ -20,6 +25,12 @@ def resolve_str_promise_attribute(ctx: AttributeContext) -> MypyType:
2025
str_info = helpers.lookup_fully_qualified_typeinfo(helpers.get_typechecker_api(ctx), "builtins.str")
2126
assert str_info is not None
2227
str_type = Instance(str_info, [])
28+
29+
# TODO: [mypy 1.16+] Remove this workaround for passing `msg` to `analyze_member_access()`.
30+
extra: dict[str, Any] = {}
31+
if mypy_version_info < (1, 16):
32+
extra["msg"] = ctx.api.msg
33+
2334
return analyze_member_access(
2435
method_name,
2536
str_type,
@@ -28,7 +39,7 @@ def resolve_str_promise_attribute(ctx: AttributeContext) -> MypyType:
2839
is_super=False,
2940
# operators are already handled with magic methods defined in the stubs for _StrPromise
3041
is_operator=False,
31-
msg=ctx.api.msg,
3242
original_type=ctx.type,
3343
chk=helpers.get_typechecker_api(ctx),
44+
**extra,
3445
)

0 commit comments

Comments
 (0)