Skip to content

Commit 1d8c3fe

Browse files
committed
Also augmented assignment
1 parent 00598f0 commit 1d8c3fe

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

crates/ty_python_semantic/resources/mdtest/liskov.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ class Base:
7474
class RegularClassAttributeOverride(Base):
7575
class_attr = 1
7676

77+
class AugmentedClassAttributeOverride(Base):
78+
class_attr = 1
79+
class_attr += 1
80+
7781
class RegularClassAttributeBase:
7882
attr = 1
7983

crates/ty_python_semantic/src/types/overrides.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,12 +499,16 @@ fn check_class_declaration<'db>(
499499
&& subclass_kind != superclass_variable_kind
500500
{
501501
// An unannotated class-body assignment can inherit an overridden `ClassVar`
502-
// declaration instead of introducing a conflicting instance variable.
502+
// declaration instead of introducing a conflicting instance variable. This
503+
// also applies to augmented assignments after the initial class-body
504+
// assignment, e.g. `epilog = "..."; epilog += "..."`.
503505
if subclass_kind == VariableKind::Instance
504506
&& superclass_variable_kind == VariableKind::Class
505-
&& first_reachable_definition
506-
.kind(db)
507-
.is_unannotated_assignment()
507+
&& matches!(
508+
first_reachable_definition.kind(db),
509+
DefinitionKind::Assignment(_)
510+
| DefinitionKind::AugmentedAssignment(_)
511+
)
508512
{
509513
continue;
510514
}

0 commit comments

Comments
 (0)