GeezerVison is showing github.com — Multitoken substitution · Issue #74 · python-trio/unasync
Multitoken substitution #74
Description
Hey 👋
I recently came across unasync and wanted to commend you on this incredibly promising & useful project.
In that vein, I wanted to note that certain substitutions (notably additional_replacements={"@pytest.mark.trio": ""}) effectively results in a no-op as a result of the tokenization converting @pytest.mark.trio to the tokens @pytest, mark and trio.
Although token-based execution is theoretically superior, it adds a layer of complexity that httpcore's unasync.py doesn't face.
My recommendation would be to also tokenize the additional_replacements and attempt to match the token streams.
Happy to implement it once we're aligned on a solution.
Activity
sethmlarson commented on May 7, 2021
Multi-token replacements are a little more complex, but if you want a workaround for this now you can use the following:
# pytest marks
pytest_mark_trio = pytest.mark.trio
def pytest_mark_sync(f):
return f # no-op decorator
# unasync config
additional_replacements={"pytest_mark_trio": "pytest_mark_sync"}
# test files
@pytest_mark_trio
async def test_example(): ...
@pytest_mark_sync
def test_example(): ...
johtso commented on May 7, 2021
david-alm commented on May 7, 2021
Appreciate the workarounds. Just flagging that this doesn't behave as expected.
I'll PR this enhancement if you're okay with it.
sethmlarson commented on May 7, 2021
Metadata
Metadata
Development
No branches or pull requestsIssue actions