Initialize Leaf bracket depth#5215
Conversation
|
Thank you for addressing this issue so quickly. Not in my wildest dreams did i expect that kinda turnaround. This PR is sufficient to resolve this particular crash. But this entire class of issues can all be resolved! 100s or 1000s of them.
For example, before Then continue for the entire Leaf interface, not just the one attribute. Of course, rtfm pytest-mypy-plugins. Can then visit types-strictyaml to see more realistic static typing tests. |
|
Thanks! One nit: could you put the test in an existing file instead of making a new one? Please also add a python test case file that provides an example of code that crashes without this fix. |
Description
Fixes #5214.
Leaf.bracket_depthis annotated and later read by formatting code, but a newly created leaf did not initialize the instance attribute until bracket tracking visited it. This initializes new leaves with depth0, matching the default pre-bracket-tracking state, and adds a small regression test covering the leaf metadata defaults.Checklist
--previewstyle, following stability policy?CHANGES.mdnecessary?No style or documentation changes are needed for this crash fix.
Tests
.venv/bin/python -m pytest tests/test_pytree.py.venv/bin/python -m pytest tests/test_format.py -k fmtskip_after_bracket_with_comment.venv/bin/python -m black --check src/blib2to3/pytree.py tests/test_pytree.py