Skip to content

Commit 54e6de0

Browse files
committed
Add is_lvalue attribute to plugin AttributeContext
1 parent 16ba7f4 commit 54e6de0

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

mypy/checkmember.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,11 @@ def analyze_member_var_access(
572572
if hook:
573573
result = hook(
574574
AttributeContext(
575-
get_proper_type(mx.original_type), result, mx.context, mx.chk
575+
get_proper_type(mx.original_type),
576+
result,
577+
mx.is_lvalue,
578+
mx.context,
579+
mx.chk,
576580
)
577581
)
578582
return result
@@ -829,7 +833,9 @@ def analyze_var(
829833
result = analyze_descriptor_access(result, mx)
830834
if hook:
831835
result = hook(
832-
AttributeContext(get_proper_type(mx.original_type), result, mx.context, mx.chk)
836+
AttributeContext(
837+
get_proper_type(mx.original_type), result, mx.is_lvalue, mx.context, mx.chk
838+
)
833839
)
834840
return result
835841

@@ -1148,7 +1154,9 @@ def apply_class_attr_hook(
11481154
) -> Type | None:
11491155
if hook:
11501156
result = hook(
1151-
AttributeContext(get_proper_type(mx.original_type), result, mx.context, mx.chk)
1157+
AttributeContext(
1158+
get_proper_type(mx.original_type), result, mx.is_lvalue, mx.context, mx.chk
1159+
)
11521160
)
11531161
return result
11541162

mypy/plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ class MethodContext(NamedTuple):
495495
class AttributeContext(NamedTuple):
496496
type: ProperType # Type of object with attribute
497497
default_attr_type: Type # Original attribute type
498+
is_lvalue: bool # Whether the attribute is the target for an assignment
498499
context: Context # Relevant location context (e.g. for error messages)
499500
api: CheckerPluginInterface
500501

0 commit comments

Comments
 (0)