Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multi-level member imports in fixes #8713

Open
charliermarsh opened this issue Nov 16, 2023 · 6 comments · Fixed by #8933
Open

Support multi-level member imports in fixes #8713

charliermarsh opened this issue Nov 16, 2023 · 6 comments · Fixed by #8933
Labels
bug Something isn't working

Comments

@charliermarsh
Copy link
Member

ruff  *.py --select TRIO115 --no-cache --fix --unsafe-fixes --preview --isolated

file content:

from trio import Event, sleep
class _RouteMethod(Enum):
    def __init__(self, token: str):
        self._headers = {
        }
    async def request(
    ):
            try:
                        if bool(resp.headers.get("X-RateLimit-Global")):
                            logger.warning(
                        )
                        await sleep(reset_after)
            except OSError as err:
                    await sleep(5)

error

/home/rafal/test/tmp_folder/F_NAME_9541977883458822252.py:12:31: TRIO115 Use `trio.lowlevel.checkpoint()` instead of `trio.sleep(0)`
Found 1 error.
[*] 1 fixable with the --fix option.

error: Fix introduced a syntax error in `/home/rafal/test/tmp_folder/F_NAME_9541977883458822252.py` with rule codes TRIO115: invalid syntax. Got unexpected token '.' at byte offset 39
---
from trio import Event, sleep, lowlevel.checkpoint
class _RouteMethod(Enum):
    def __init__(self, token: str):
        self._headers = {
        }
    async def request(
    ):
            try:
                        if bool(resp.headers.get("X-RateLimit-Global")):
                            logger.warning(
                        )
                        await lowlevel.checkpoint
            except OSError as err:
                    await sleep(5)
---

python_compressed.zip

Originally posted by @qarmin in #8402 (comment)

@charliermarsh charliermarsh self-assigned this Nov 16, 2023
@charliermarsh charliermarsh added the bug Something isn't working label Nov 16, 2023
@dhruvmanila
Copy link
Member

@charliermarsh Have you looked at this? Otherwise I can give it a look, seems like an easy fix :)

@charliermarsh charliermarsh removed their assignment Dec 1, 2023
@charliermarsh
Copy link
Member Author

@dhruvmanila - No, feel free! I don't know how hard or easy it is -- it likely requires some kind of iteration within the Importer.

@dhruvmanila
Copy link
Member

Hmm, not sure where does this import come from: from trio import Event, sleep, lowlevel.checkpoint as for me it's always from trio import Event, sleep, lowlevel.

dhruvmanila added a commit that referenced this issue Dec 1, 2023
## Summary

This PR fixes the bug where the autofix for `TRIO115` was taking the
entire arguments range for the fix which included the parenthesis as
well. This means that the fix would remove the arguments and the
parenthesis. The fix is to use the correct range.

fixes: #8713 

## Test Plan

Update existing snapshots :)
@dhruvmanila
Copy link
Member

Oh, the import was a bug in v0.1.5 which was fixed in v0.1.6.

@charliermarsh
Copy link
Member Author

I fixed this specific case, but it doesn't always do the optimal thing.

@charliermarsh charliermarsh reopened this Dec 1, 2023
@charliermarsh
Copy link
Member Author

For example, if the user has import trio.lowlevel, I don't think we leverage the fact that we can do trio.lowlevel.checkpoint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants