Skip to content

bug: UP007 should be reversed when targeting py37 #3174

@upstartjohnvandivier

Description

@upstartjohnvandivier

thanks for the library! we love it. found another issue tho, consider the class:

class Foo(TypedDict):
    bar: NotRequired[Union[bool, None]]

ruff lint throws on the property and will autofix to use a pipe operator when "UP" ruleset is selected:

    bar: NotRequired[bool | None]

this syntax is enabled only in python 3.10+ and breaks applications on an earlier version. in my case, I have pyproject.toml with the following subsnippet:

[tool.ruff]
target-version = 'py37'

two interesting asides:

  1. I am running ruff cli inside a docker container that has python 3.10 installed. hopefully ruff is smart enough to use the pyproject.toml for reference and does try to detect via the current process version
  2. i couldn't easily see documentation on how to dump or log the ruff config from inside the process, so I simply have to trust that pyproject.toml is respected and I can't really troubleshoot. I'll file a feature request to enhance ruff -V or some other mechanism

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