8000 Constant fold initializers of final variables by JukkaL · Pull Request #14283 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Constant fold initializers of final variables #14283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixes
  • Loading branch information
JukkaL committed Dec 10, 2022
commit 4fa9fd3b13d91e926830eb070c6748596b6c3840
7 changes: 7 additions & 0 deletions test-data/unit/semanal-basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(x [__main__.x])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes such as these are a side effect of making semantic analyzer tests use the constant folding logic. Previously it was disabled due to historical reasons. The actual behavior outside tests wasn't changed (for most of these test changes).

IntExpr(1)
builtins.int)
ExpressionStmt:2(
NameExpr(x [__main__.x])))

Expand All @@ -27,6 +28,7 @@ MypyFile:1(
AssignmentStmt:2(
NameExpr(z [__main__.z])
IntExpr(3)
builtins.int)
ExpressionStmt:3(
TupleExpr:3(
NameExpr(x [__main__.x])
Expand Down Expand Up @@ -63,6 +65,7 @@ MypyFile:1(
AssignmentStmt:3(
NameExpr(x [__main__.x])
IntExpr(1)
builtins.int)
FuncDef:4(
f
Block:4(
Expand Down Expand Up @@ -119,6 +122,7 @@ MypyFile:1(
AssignmentStmt:4(
NameExpr(x [__main__.x])
IntExpr(1)
builtins.int)
FuncDef:5(
g
Block:5(
Expand All @@ -136,6 +140,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(x [__main__.x])
IntExpr(1)
builtins.int)
AssignmentStmt:2(
NameExpr(x [__main__.x])
IntExpr(2))
Expand Down Expand Up @@ -165,6 +170,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(x [__main__.x])
IntExpr(1)
builtins.int)
FuncDef:2(
f
Block:2(
Expand Down Expand Up @@ -500,6 +506,7 @@ MypyFile:1(
AssignmentStmt:4(
NameExpr(x [__main__.x] = 1)
IntExpr(1)
Literal[1]?)
AssignmentStmt:5(
NameExpr(y* [__main__.y] = 1.0)
FloatExpr(1.0))
Expand Down
3 changes: 3 additions & 0 deletions test-data/unit/semanal-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ MypyFile:1(
AssignmentStmt:2(
NameExpr(x [m])
IntExpr(1)
builtins.int)
AssignmentStmt:3(
NameExpr(y* [m])
NameExpr(x [__main__.A.x]))))
Expand Down Expand Up @@ -289,6 +290,7 @@ MypyFile:1(
AssignmentStmt:3(
NameExpr(x [m])
IntExpr(1)
builtins.int))
Else(
AssignmentStmt:5(
NameExpr(x [__main__.A.x])
Expand Down Expand Up @@ -543,6 +545,7 @@ MypyFile:1(
AssignmentStmt:3(
NameExpr(X [m])
IntExpr(1)
builtins.int)
FuncDef:4(
f
Args(
Expand Down
11 changes: 11 additions & 0 deletions test-data/unit/semanal-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(x [__main__.x])
IntExpr(1)
builtins.int)
ExpressionStmt:2(
MemberExpr:2(
NameExpr(x [__main__.x])
Expand Down Expand Up @@ -82,6 +83,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(x [__main__.x])
IntExpr(1)
builtins.int)
ExpressionStmt:2(
UnaryExpr:2(
-
Expand Down Expand Up @@ -189,6 +191,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(a [__main__.a])
IntExpr(0)
builtins.int)
ExpressionStmt:2(
ListComprehension:2(
GeneratorExpr:2(
Expand Down Expand Up @@ -225,6 +228,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(a [__main__.a])
IntExpr(0)
builtins.int)
AssignmentStmt:2(
NameExpr(b* [__main__.b])
ListComprehension:2(
Expand All @@ -242,6 +246,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(a [__main__.a])
IntExpr(0)
builtins.int)
ExpressionStmt:2(
SetComprehension:2(
GeneratorExpr:2(
Expand All @@ -260,6 +265,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(a [__main__.a])
IntExpr(0)
builtins.int)
AssignmentStmt:2(
NameExpr(b* [__main__.b])
SetComprehension:2(
Expand All @@ -277,6 +283,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(a [__main__.a])
IntExpr(0)
builtins.int)
ExpressionStmt:2(
DictionaryComprehension:2(
NameExpr(x [l])
Expand All @@ -295,6 +302,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(a [__main__.a])
IntExpr(0)
builtins.int)
AssignmentStmt:2(
NameExpr(b* [__main__.b])
DictionaryComprehension:2(
Expand All @@ -315,6 +323,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(a [__main__.a])
IntExpr(0)
builtins.int)
ExpressionStmt:2(
GeneratorExpr:2(
NameExpr(x [l])
Expand All @@ -329,6 +338,7 @@ MypyFile:1(
AssignmentStmt:1(
Nam 9E7A eExpr(a [__main__.a])
IntExpr(0)
builtins.int)
ExpressionStmt:2(
GeneratorExpr:2(
NameExpr(x [l])
Expand All @@ -347,6 +357,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(x [__main__.x])
IntExpr(0)
builtins.int)
ExpressionStmt:2(
LambdaExpr:2(
Block:2(
Expand Down
3 changes: 3 additions & 0 deletions test-data/unit/semanal-modules.test
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ y = 1
[file m/n.py]
x = 1
[out]
builtins.int))
MypyFile:1(
Import:1(m.n)
ExpressionStmt:2(
Expand Down Expand Up @@ -441,6 +442,7 @@ MypyFile:1(
NameExpr(m)
n [m.n])
b [m.n.b]))
builtins.int)
ExpressionStmt:4(
MemberExpr:4(
NameExpr(m)
Expand Down Expand Up @@ -621,6 +623,7 @@ from . import z
[file m/z.py]
y = 1
[out]
builtins.int))
MypyFile:1(
Import:1(m.x)
ExpressionStmt:2(
Expand Down
9 changes: 9 additions & 0 deletions test-data/unit/semanal-python310.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(x [__main__.x])
IntExpr(1)
builtins.int)
MatchStmt:2(
NameExpr(x [__main__.x])
Pattern(
Expand All @@ -30,6 +31,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(x [__main__.x])
IntExpr(1)
builtins.int)
MatchStmt:2(
NameExpr(x [__main__.x])
Pattern(
Expand All @@ -51,6 +53,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(x [__main__.x])
IntExpr(1)
builtins.int)
MatchStmt:2(
NameExpr(x [__main__.x])
Pattern(
Expand Down Expand Up @@ -80,6 +83,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(x [__main__.x])
IntExpr(1)
builtins.int)
MatchStmt:2(
NameExpr(x [__main__.x])
Pattern(
Expand All @@ -101,6 +105,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(x [__main__.x])
IntExpr(1)
builtins.int)
MatchStmt:2(
NameExpr(x [__main__.x])
Pattern(
Expand All @@ -123,6 +128,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(x [__main__.x])
IntExpr(1)
builtins.int)
AssignmentStmt:2(
NameExpr(a* [__main__.a])
IntExpr(1))
Expand All @@ -146,6 +152,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(x [__main__.x])
IntExpr(1)
builtins.int)
MatchStmt:2(
NameExpr(x [__main__.x])
Pattern(
Expand All @@ -166,6 +173,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(x [__main__.x])
IntExpr(1)
builtins.int)
MatchStmt:2(
NameExpr(x [__main__.x])
Pattern(
Expand Down Expand Up @@ -193,6 +201,7 @@ MypyFile:1(
AssignmentStmt:3(
NameExpr(x [__main__.x])
IntExpr(1)
builtins.int)
MatchStmt:4(
NameExpr(x [__main__.x])
Pattern(
Expand Down
9 changes: 9 additions & 0 deletions test-data/unit/semanal-statements.test
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(x [__main__.x])
IntExpr(1)
builtins.int)
IfStmt:2(
If(
NameExpr(x [__main__.x]))
Expand Down Expand Up @@ -324,6 +325,7 @@ MypyFile:1(
Lvalues(
NameExpr(x* [__main__.x])
NameExpr(y* [__main__.y]))
IntExpr(1))
IntExpr(1)
AssignmentStmt:2(
NameExpr(xx [__main__.xx])
Expand Down Expand Up @@ -410,6 +412,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(x [__main__.x])
IntExpr(1)
builtins.int)
AssignmentStmt:2(
TupleExpr:2(
NameExpr(y* [__main__.y]))
Expand Down Expand Up @@ -438,6 +441,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(x [__main__.x])
IntExpr(1)
builtins.int)
AssignmentStmt:2(
TupleExpr:2(
NameExpr(y* [__main__.y])
Expand All @@ -452,6 +456,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(x [__main__.x])
IntExpr(1)
builtins.int)
AssignmentStmt:2(
TupleExpr:2(
NameExpr(y* [__main__.y])
Expand All @@ -470,6 +475,7 @@ MypyFile:1(
AssignmentStmt:1(
NameExpr(x [__main__.x])
IntExpr(1)
builtins.int)
IfStmt:2(
If(
NameExpr(x [__main__.x]))
Expand Down Expand Up @@ -499,6 +505,7 @@ MypyFile:1(
NameExpr(x* [__main__.x])
NameExpr(y* [__main__.y]))
IntExpr(1))
builtins.int)
DelStmt:2(
IndexExpr:2(
NameExpr(x [__main__.x])
Expand Down Expand Up @@ -963,6 +970,7 @@ MypyFile:1(
AssignmentStmt:3(
NameExpr(x' [__main__.x'])
IntExpr(0)
builtins.int)
ExpressionStmt:4(
CallExpr:4(
NameExpr(f [__main__.f])
Expand Down Expand Up @@ -1048,6 +1056,7 @@ MypyFile:1(
AssignmentStmt:2(
NameExpr(x [__main__.x])
IntExpr(0)
builtins.int)
ExpressionStmt:3(
NameExpr(x [__main__.x]))
ClassDef:4(
Expand Down
0