python-trio / python-trio/flake8-async
first transform, then visit, to not get incorrect line markers
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 26
- Forks
- 10
- PR merge metrics
- No merged PRs in 30d
Description
low-priority QoL - unless flake8-trio is used in automated environments.
Failing test:
def test_line_numbers_match_end_result():
text = """import trio
with trio.move_on_after(10):
...
trio.sleep(0)
"""
plugin = Plugin.from_source(text)
initialize_options(plugin, args=["--enable=TRIO100,TRIO115", "--autofix=TRIO100"])
errors = tuple(plugin.run())
new_source = plugin.module.code
assert errors[1].line == plugin.module.code.split('\n').index('trio.sleep(0)')+1
the assertion fails with 5 != 4 as the line numbers of objects are never updated once parsed when initiating the plugin.
The best way to fix this would probably, as the header suggest, be to first make a pass where all enabled autofixers are run - with autofixed errors being printed out with old and/or no line markers. Then the file is reparsed, and enabled visitors are run on the file.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the failing test test_line_numbers_match_end_result and trace Plugin.from_source, initialize_options, and plugin.run. Check how autofixers and visitors are sequenced and how line markers are retained. Done means autofixes run before reparsing, visitors see the transformed source, and the assertion reports the correct line for trio.sleep(0).
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100