GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Multitoken substitution · Issue #74 · python-trio/unasync

Multitoken substitution #74

New issue
Copy link
New issue
Copy link
Open
Open
Multitoken substitution#74
Copy link

Description

@david-alm
david-alm
opened on May 7, 2021
Issue body actions

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.

Reacted by Johannes

Activity

  1. sethmlarson commented on May 7, 2021

    @sethmlarson
    sethmlarson
    on May 7, 2021
    Contributor
    More actions

    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(): ...
    
    Reacted by david-alm
  2. johtso commented on May 7, 2021

    @johtso
    johtso
    on May 7, 2021
    More actions

    I'm doing something even more basic, just replacing the trio or asyncio token with sync..

    https://github.com/johtso/httpx-caching/blob/master/tests/_async/test_chunked_response.py#L11

    https://github.com/johtso/httpx-caching/blob/master/gen_sync.py#L24

    I guess that's probably not the best idea, and only works because I'm not referencing trio or asyncio directly anywhere. But yeah, if that's an issue, you can just assign it to a variable to make it more explicit.

    Reacted by david-alm
  3. david-alm commented on May 7, 2021

    @david-alm
    david-alm
    on May 7, 2021
    Author
    More actions

    Appreciate the workarounds. Just flagging that this doesn't behave as expected.
    I'll PR this enhancement if you're okay with it.

    Reacted by Johannes
  4. sethmlarson commented on May 7, 2021

    @sethmlarson
    sethmlarson
    on May 7, 2021
    Contributor
    More actions

    That'd be great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.