Skip to content

fix(internals): Act upon and resolve Python 3.15 AST deprecations#1668

Merged
qartik merged 10 commits intomainfrom
ks-fix-ast-name-field-types
Apr 20, 2026
Merged

fix(internals): Act upon and resolve Python 3.15 AST deprecations#1668
qartik merged 10 commits intomainfrom
ks-fix-ast-name-field-types

Conversation

@qartik
Copy link
Copy Markdown
Member

@qartik qartik commented Apr 16, 2026

Closes #1316.

Resolves warnings like these:

guppylang_internals/nodes.py:52: DeprecationWarning: Field 'def_id' is missing from GlobalName._field_types. This will become an error in Python 3.15.
    super().__init__(id=id)

guppylang_internals/nodes.py:79: DeprecationWarning: Field 'var' is missing from DummyGenericParamValue._field_types. This will become an error in Python 3.15.
    super().__init__(id=id)

guppylang_internals/nodes.py:718: DeprecationWarning: Dagger.__init__ got an unexpected keyword argument 'source'. Support for arbitrary keyword arguments is deprecated and will be removed in Python 3.15.
    super().__init__(**node.__dict__)

guppylang_internals/nodes.py:734: DeprecationWarning: Control.__init__ got an unexpected keyword argument 'func'. Support for arbitrary keyword arguments is deprecated and will be removed in Python 3.15.
    super().__init__(**node.__dict__)

guppylang_internals/nodes.py:734: DeprecationWarning: Field 'ctrl' is missing from Control._field_types. This will become an error in Python 3.15.
    super().__init__(**node.__dict__)

guppylang_internals/nodes.py:677: DeprecationWarning: NestedFunctionDef.__init__ got an unexpected keyword argument 'docstring'. Support for arbitrary keyword arguments is deprecated and will be removed in Python 3.15.
    super().__init__(*args, **kwargs)

Summary

  • add guarded _field_types handling for custom ast.Name, ast.Call, and ast.FunctionDef subclasses in guppylang_internals.nodes
  • pass custom AST fields through base constructors where Python 3.15 now validates them
  • stop cloning modifier nodes via super().__init__(**node.__dict__) for Dagger, Control, and Power
  • preserve source-location metadata explicitly with set_location_from(...)

Why

Python 3.14 warns about AST constructor patterns that will become errors in Python 3.15, including:

  • custom fields missing from _field_types
  • arbitrary keyword arguments passed into AST constructors

This change updates the affected custom AST nodes in guppylang_internals.nodes so they no longer rely on deprecated constructor behavior.

Validation

  • uv run pytest -W default::DeprecationWarning

Notes

The only remaining DeprecationWarning entries from the full test run are Python stdlib multiprocessing fork() warnings in tests/test_guppy_decoupled.py, not AST-node warnings from Guppy.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.49%. Comparing base (f8cf7bb) to head (a5af57f).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1668      +/-   ##
==========================================
- Coverage   93.55%   93.49%   -0.07%     
==========================================
  Files         133      133              
  Lines       12641    12704      +63     
==========================================
+ Hits        11826    11877      +51     
- Misses        815      827      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 16, 2026

🐰 Bencher Report

Branchks-fix-ast-name-field-types
TestbedLinux

🚨 1 Alert

BenchmarkMeasure
Units
ViewBenchmark Result
(Result Δ%)
Upper Boundary
(Limit %)
tests/benchmarks/test_big_array.py::test_big_array_executableLatency
seconds (s)
📈 plot
🚷 threshold
🚨 alert (🔔)
8.98 s
(+6.97%)Baseline: 8.39 s
8.81 s
(101.87%)

Click to view all benchmark results
BenchmarkLatencyBenchmark Result
microseconds (µs)
(Result Δ%)
Upper Boundary
microseconds (µs)
(Limit %)
tests/benchmarks/test_big_array.py::test_big_array_check📈 view plot
🚷 view threshold
730,910.49 µs
(-25.73%)Baseline: 984,129.13 µs
1,033,335.59 µs
(70.73%)
tests/benchmarks/test_big_array.py::test_big_array_compile📈 view plot
🚷 view threshold
1,899,637.98 µs
(-8.61%)Baseline: 2,078,618.41 µs
2,182,549.33 µs
(87.04%)
tests/benchmarks/test_big_array.py::test_big_array_executable📈 view plot
🚷 view threshold
🚨 view alert (🔔)
8,975,211.90 µs
(+6.97%)Baseline: 8,390,703.26 µs
8,810,238.43 µs
(101.87%)

tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_check📈 view plot
🚷 view threshold
103,280.59 µs
(-3.51%)Baseline: 107,041.03 µs
112,393.08 µs
(91.89%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_compile📈 view plot
🚷 view threshold
214,098.36 µs
(-7.17%)Baseline: 230,622.97 µs
242,154.12 µs
(88.41%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_executable📈 view plot
🚷 view threshold
982,064.79 µs
(-19.52%)Baseline: 1,220,334.81 µs
1,281,351.55 µs
(76.64%)
tests/benchmarks/test_prelude.py::test_import_guppy📈 view plot
🚷 view threshold
44.47 µs
(-14.43%)Baseline: 51.97 µs
54.57 µs
(81.50%)
tests/benchmarks/test_queue_push_pop.py::test_queue_push_benchmark📈 view plot
🚷 view threshold
481,824.42 µs
(+3.85%)Baseline: 463,977.09 µs
487,175.94 µs
(98.90%)
tests/benchmarks/test_queue_push_pop.py::test_queue_push_pop_benchmark📈 view plot
🚷 view threshold
640,689.19 µs
(+4.03%)Baseline: 615,868.92 µs
646,662.37 µs
(99.08%)
🐰 View full continuous benchmarking report in Bencher

@qartik qartik marked this pull request as ready for review April 16, 2026 20:49
@qartik qartik requested a review from a team as a code owner April 16, 2026 20:49
@qartik qartik requested a review from hsemenenko April 16, 2026 20:49
@ss2165
Copy link
Copy Markdown
Member

ss2165 commented Apr 17, 2026

@qartik Does this address #1316?

@maximilianruesch maximilianruesch changed the title fix(internals): avoid Python 3.15 AST name warnings fix(internals): Avoid Python 3.15 AST name warnings Apr 17, 2026
@qartik
Copy link
Copy Markdown
Member Author

qartik commented Apr 17, 2026

@qartik Does this address #1316?

It doesn't, but I can expand this PR to handle those warnings as well.

I noticed the warnings covered in this PR on the internal compiler's tests. Updated the PR desc to be more explicit.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 17, 2026

🐰 Bencher Report

Branchks-fix-ast-name-field-types
TestbedLinux
Click to view all benchmark results
Benchmarkhugr_bytesBenchmark Result
bytes x 1e3
(Result Δ%)
Upper Boundary
bytes x 1e3
(Limit %)
hugr_nodesBenchmark Result
nodes x 1e3
(Result Δ%)
Upper Boundary
nodes x 1e3
(Limit %)
tests/benchmarks/test_big_array.py::test_big_array_compile📈 view plot
🚷 view threshold
158.77 x 1e3
(0.00%)Baseline: 158.77 x 1e3
160.36 x 1e3
(99.01%)
📈 view plot
🚷 view threshold
6.64 x 1e3
(0.00%)Baseline: 6.64 x 1e3
6.71 x 1e3
(99.01%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_compile📈 view plot
🚷 view threshold
27.53 x 1e3
(0.00%)Baseline: 27.53 x 1e3
27.81 x 1e3
(99.01%)
📈 view plot
🚷 view threshold
1.07 x 1e3
(0.00%)Baseline: 1.07 x 1e3
1.08 x 1e3
(99.01%)
🐰 View full continuous benchmarking report in Bencher

@qartik qartik changed the title fix(internals): Avoid Python 3.15 AST name warnings fix(internals): cover Python 3.15 AST deprecations Apr 17, 2026
@qartik qartik changed the title fix(internals): cover Python 3.15 AST deprecations fix(internals): Cover Python 3.15 AST deprecations Apr 17, 2026
@qartik qartik requested a review from ss2165 April 17, 2026 13:06
@maximilianruesch maximilianruesch self-requested a review April 20, 2026 06:33
@maximilianruesch maximilianruesch changed the title fix(internals): Cover Python 3.15 AST deprecations fix(internals): Act upon and resolve Python 3.15 AST deprecations Apr 20, 2026
Comment thread guppylang-internals/src/guppylang_internals/nodes.py Outdated
Comment thread guppylang-internals/src/guppylang_internals/nodes.py Outdated
Comment thread guppylang-internals/src/guppylang_internals/nodes.py Outdated
Comment thread guppylang-internals/src/guppylang_internals/nodes.py Outdated
Comment thread guppylang-internals/src/guppylang_internals/nodes.py Outdated
Comment thread guppylang-internals/src/guppylang_internals/nodes.py
Comment thread guppylang-internals/src/guppylang_internals/nodes.py
Comment thread guppylang-internals/src/guppylang_internals/nodes.py
Comment thread tests/test_ast_nodes.py Outdated
Comment thread tests/test_ast_nodes.py Outdated
@qartik qartik requested a review from hsemenenko April 20, 2026 13:04
@qartik qartik added this pull request to the merge queue Apr 20, 2026
Merged via the queue into main with commit 618ce5b Apr 20, 2026
13 of 17 checks passed
@qartik qartik deleted the ks-fix-ast-name-field-types branch April 20, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Arbitrary kwargs in ast nodes is deprecated

4 participants