|
17 | 17 | from mypy.expandtype import expand_type_by_instance, expand_type, freshen_function_type_vars
|
18 | 18 | from mypy.infer import infer_type_arguments
|
19 | 19 | from mypy.typevars import fill_typevars
|
20 |
| -from mypy.plugin import Plugin |
| 20 | +from mypy.plugin import Plugin, AttributeContext |
21 | 21 | from mypy import messages
|
22 | 22 | from mypy import subtypes
|
23 | 23 | MYPY = False
|
@@ -78,7 +78,7 @@ def analyze_member_access(name: str,
|
78 | 78 | assert isinstance(method, OverloadedFuncDef)
|
79 | 79 | first_item = cast(Decorator, method.items[0])
|
80 | 80 | return analyze_var(name, first_item.var, typ, info, node, is_lvalue, msg,
|
81 |
| - original_type, not_ready_callback, chk.plugin) |
| 81 | + original_type, not_ready_callback, chk=chk) |
82 | 82 | if is_lvalue:
|
83 | 83 | msg.cant_assign_to_method(node)
|
84 | 84 | signature = function_type(method, builtin_type('builtins.function'))
|
@@ -228,9 +228,8 @@ def analyze_member_var_access(name: str, itype: Instance, info: TypeInfo,
|
228 | 228 | v = vv.var
|
229 | 229 |
|
230 | 230 | if isinstance(v, Var):
|
231 |
| - plugin = chk.plugin if chk is not None else None |
232 | 231 | return analyze_var(name, v, itype, info, node, is_lvalue, msg,
|
233 |
| - original_type, not_ready_callback, plugin) |
| 232 | + original_type, not_ready_callback, chk=chk) |
234 | 233 | elif isinstance(v, FuncDef):
|
235 | 234 | assert False, "Did not expect a function"
|
236 | 235 | elif not v and name not in ['__getattr__', '__setattr__', '__getattribute__']:
|
@@ -272,8 +271,8 @@ def analyze_member_var_access(name: str, itype: Instance, info: TypeInfo,
|
272 | 271 |
|
273 | 272 | def analyze_var(name: str, var: Var, itype: Instance, info: TypeInfo, node: Context,
|
274 | 273 | is_lvalue: bool, msg: MessageBuilder, original_type: Type,
|
275 |
| - not_ready_callback: Callable[[str, Context], None], |
276 |
| - plugin: Optional[Plugin]) -> Type: |
| 274 | + not_ready_callback: Callable[[str, Context], None], *, |
| 275 | + chk: 'mypy.checker.TypeChecker') -> Type: |
277 | 276 | """Analyze access to an attribute via a Var node.
|
278 | 277 |
|
279 | 278 | This is conceptually part of analyze_member_access and the arguments are similar.
|
@@ -320,11 +319,10 @@ def analyze_var(name: str, var: Var, itype: Instance, info: TypeInfo, node: Cont
|
320 | 319 | not_ready_callback(var.name(), node)
|
321 | 320 | # Implicit 'Any' type.
|
322 | 321 | result = AnyType()
|
323 |
| - if plugin: |
324 |
| - fullname = '{}.{}'.format(var.info.fullname(), name) |
325 |
| - hook = plugin.get_attribute_hook(fullname) |
326 |
| - if hook: |
327 |
| - result = hook(original_type, result) |
| 322 | + fullname = '{}.{}'.format(var.info.fullname(), name) |
| 323 | + hook = chk.plugin.get_attribute_hook(fullname) |
| 324 | + if hook: |
| 325 | + result = hook(AttributeContext(original_type, result, node, chk)) |
328 | 326 | return result
|
329 | 327 |
|
330 | 328 |
|
|
0 commit comments