1+ from typing import Any
2+
13from mypy .checkmember import analyze_member_access
24from mypy .errorcodes import ATTR_DEFINED
35from mypy .nodes import CallExpr , MemberExpr
46from mypy .plugin import AttributeContext
57from mypy .types import AnyType , Instance , TypeOfAny
68from mypy .types import Type as MypyType
9+ from mypy .version import __version__ as mypy_version
710
811from mypy_django_plugin .lib import helpers
912
13+ mypy_version_info = tuple (map (int , mypy_version .partition ("+" )[0 ].split ("." )))
14+
1015
1116def 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