Skip to content

UP007: opt out of Optional #4858

@Fogapod

Description

@Fogapod

Hello, currently UP007 covers both Union[a, b, c] -> a | b | c and Optional[a] -> a | None.
Personally i find Optional to be more readable and PEP 604 does not deprecate this syntax either.

I'm not sure how it could be changed without breaking changes. I see 2 ways:

  • UP007 stops reporting Optional, keeps reporting Union and later added rules
  • UP039 is added which only reports Optional

The downside of this is that it forces people to update config to get previous behavior if they didn't have entire UP category enabled. Alternative is:

  • UP007 remains unchanged
  • UP039 is added which reports Union and later added rules

This might be even worse because

  1. for people with UP in config it does double work
  2. if someone had UP enabled and UP007 ignored, the Union lint would reappear (although I'd assume most people who do this because of Optional)

pyupgrade author made it clear in multiple issues that they are not going to change this asottile/pyupgrade#390 (comment). don't know how much you are willing to deviate from "upstream" for cases like this but it would be a nice addition

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