Skip to content

Commit 6e1a5e6

Browse files
zyvbrianhelba
authored andcommitted
Add tests for ClassVar-annotated Migration fields (typeddjango#2702)
For the fields "initial" and "atomic", this is strictly correct, as these are set on the class, not the instance. For "operations", "dependencies", "run_before", and "replaces", Django intentionally copies the class attributes to the instance during construction. However, annotating the attributes as either (using "|") class or instance variables causes MyPy to issue the warning: "Cannot override instance variable (previously declared on base class "Migration") with class variable". Since Django projects will nearly always override these as class variables, annotate them as such. Signed-off-by: Brian Helba <[email protected]> Signed-off-by: Yury V. Zaytsev <[email protected]> Co-authored-by: Brian Helba <[email protected]>
1 parent c3e5952 commit 6e1a5e6

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
- case: explicit
2+
main: |
3+
from typing import ClassVar, List
4+
from django.db import migrations
5+
from django.db.migrations.operations.base import Operation
6+
7+
class Migration(migrations.Migration):
8+
operations: ClassVar[List[Operation]] = []
9+
initial: ClassVar[bool] = True
10+
11+
- case: explicit_incorrect
12+
expect_fail: true
13+
main: |
14+
from typing import ClassVar, List
15+
from django.db import migrations
16+
from django.db.migrations.operations.base import Operation
17+
18+
class Migration(migrations.Migration):
19+
operations: List[Operation] = []
20+
initial: bool = True
21+
22+
- case: implicit
23+
main: |
24+
from django.db import migrations
25+
26+
class Migration(migrations.Migration):
27+
operations = []
28+
initial = True

0 commit comments

Comments
 (0)