Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: astral-sh/ruff
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 00802b1fdaf6ace186c8a87f21556d6fadc427aa
Choose a base ref
...
head repository: astral-sh/ruff
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ba22f95c62933fa695f400ea54f8342347737508
Choose a head ref
  • 4 commits
  • 5 files changed
  • 1 contributor

Commits on Nov 9, 2023

  1. ruff_linter: tweak detection logic for TimeoutErrorAlias

    Previously, this lint had its alias detection logic a little
    backwards. That is, for Python 3.11+, it would *only* detect
    asyncio.TimeoutError as an alias, but it should have also detected
    socket.timeout as an alias. And in Python <3.11, it would falsely
    detect asyncio.TimeoutError as an alias where it should have only
    detected socket.timeout as an alias.
    
    We fix it so that both asyncio.TimeoutError and socket.timeout are
    detected as aliases in Python 3.11+, and only socket.timeout is
    detected as an alias in Python 3.10.
    BurntSushi committed Nov 9, 2023
    Configuration menu
    Copy the full SHA
    1fd9d63 View commit details
    Browse the repository at this point in the history
  2. ruff_linter: assert that TimeoutErrorAlias only runs on 3.10+

    Without this assert, the lint could falsely trigger a safe fix
    that is actually unsafe if the higher level logic calling the lint
    changes. That is, right now, the lint is only invoked for 3.10+
    so everything is fine, but nothing is stopping that from changing.
    So we make the assumption clear: if it changes, then we should get
    a pretty loud panic.
    BurntSushi committed Nov 9, 2023
    Configuration menu
    Copy the full SHA
    ea06087 View commit details
    Browse the repository at this point in the history
  3. ruff_linter: add asyncio.TimeoutError regression test for Python 3.10+

    This new test checks that safe fixes are not suggested for replacing
    asyncio.TimeoutError with TimeoutError in Python <3.11. Namely, before
    3.11, these were distinct types. So switching from asyncio.TimeoutError
    to TimeoutError could result in a change of semantics.
    BurntSushi committed Nov 9, 2023
    Configuration menu
    Copy the full SHA
    7043846 View commit details
    Browse the repository at this point in the history
  4. ruff_linter: permit asyncio.TimeoutError as an unsafe fix for <3.11

    This commit tweaks the TimeoutErrorAlias lint to suggest
    asyncio.TimeoutError in Python <3.11, but only as an unsafe fix. Namely,
    in <3.11, asyncio.TimeoutError is not an alias and thus the
    transformation could change the semantics of the program.
    
    In the case where there is a tuple containing both safe and unsafe
    fixes, I decided to keep it as a single suggested fix and made it
    overall unsafe. So for example, if Ruff sees this code in Python 3.10:
    
        try:
          pass
        except (asyncio.TimeoutError, socket.timeout):
          pass
    
    Then it will suggest this as an unsafe fix:
    
        try:
          pass
        except TimeoutError:
          pass
    
    It could, though, suggest this as a safe fix:
    
        try:
          pass
        except (asyncio.TimeoutError, TimeoutError):
          pass
    
    since socket.timeout became an alias of TimeoutError in Python 3.10.
    
    I opted not to go this route because it wasn't obvious to me that it was
    worth it.
    
    Fixes #8565
    BurntSushi committed Nov 9, 2023
    Configuration menu
    Copy the full SHA
    ba22f95 View commit details
    Browse the repository at this point in the history
Loading