Skip to content

RUF013: unproper handling of quotes around annotations #5231

@Alexerson

Description

@Alexerson

The new rule RUF013 doesn’t properly handle string annotations.

I would expect the following to be fine:

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from datetime import datetime

def last_value(timestamp: 'datetime | None'=None) -> float ...

but with the latest version, I get: RUF013 [*] PEP 484 prohibits implicit `Optional` and the --fix version will replace it by:

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from datetime import datetime

def last_value(timestamp: 'datetime | None' |None=None) -> float ...

which is not valid and will give me:
TypeError: unsupported operand type(s) for |: 'str' and 'NoneType'

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions