exceptions raised before calling `task_status.started` loses cause & context
This snippet eats cause&context
https://github.com/python-trio/trio/blob/9c909fa10d7a9d9e1cfd019725f826848d05bf81/src/trio/_core/_run.py#L1387-L1389
a la https://flake8-async.readthedocs.io/en/latest/rules.html#async123
we currently only run the ruff reimplementation of flake8-async, which hasn't added that rule. So we should maybe consider running flake8-async as well, disabling any rules that ruff handles [better], or are noisy.
It should make use of trio._util.raise_saving_context.
repro:
import trio
async def task(task_status: trio.TaskStatus) -> None:
e = ValueError("foo")
e.__cause__ = SyntaxError("bar")
e.__context__ = TypeError("baz")
raise e
async def main() -> None:
async with trio.open_nursery() as nursery:
await nursery.start(task)
try:
trio.run(main)
except ExceptionGroup as excgroup:
# should be SyntaxError, is None
print(excgroup.exceptions[0].__cause__)
# should be TypeError, is the exceptiongroup
print(repr(excgroup.exceptions[0].__context__))
I was looking at flake8-async:
- we would need to bring in flake8 if we want to ignore the test directories?
- I think the tags are out of sync -- would pre-commit really work?
If those are bugs I can go make issues. (also generally theres a lot of errors raised...)
we would need to bring in flake8 if we want to ignore the test directories?
we can use the pre-commit files or exclude directives to exclude them
I think the tags are out of sync -- would pre-commit really work?
if that is a problem I would love to know so I can fix it!
we can use the pre-commit
filesorexcludedirectives to exclude them
I was hoping to maybe be able to run it as a command, but this makes enough sense to me.
if that is a problem I would love to know so I can fix it!
Yeah for instance the tag referenced on the docs doesn't exist:
(.venv) PS C:\Users\A5rocks\Documents\trio> pre-commit run -a
[INFO] Initializing environment for https://github.com/python-trio/flake8-async.
An unexpected error has occurred: CalledProcessError: command: ('C:\\Program Files\\Git\\cmd\\git.EXE', 'checkout', '25.5.2')
return code: 1
stdout: (none)
stderr:
error: pathspec '25.5.2' did not match any file(s) known to git
Check the log at C:\Users\A5rocks\.cache\pre-commit\pre-commit.log
This isn't really a problem (we can just use old versions in pre-commit, or maybe even commit hashes?) but it's suboptimal.
whelp, it appears I broke git tagging in https://github.com/python-trio/flake8-async/pull/321 thank you, will fix!
EDIT: fixing in https://github.com/python-trio/flake8-async/pull/385