Skip to content

UP007 crashes with TypeError on all version of Python prior to 3.14 for Optional[typing.NamedTuple] #18619

Open
@tleonhardt

Description

@tleonhardt

Summary

Rule UP007 which replaces Union type hints with | and Optional[foo] with foo | None crashes on all versions of Python including the latest ones under the very specific circumstance of replacing Optional[typing.NamedTuple] with typing.NamedTuple | None.

The error is:

TypeError: unsupported operand type(s) for |: `function` and `NoneType`

I tested on Python 3.11, 3.13 saw identical behavior in all cases. It does work fine on 3.14 due to deferred type evaluation.

Version

ruff 0.11.13 as installed from uv

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedContributions especially welcomeruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions