Skip to content

Commit

Permalink
Consider single element subscript expr for implicit optional (#5717)
Browse files Browse the repository at this point in the history
## Summary

Consider single element subscript expr for implicit optional.

On `main`, the cases where there is only a single element in the
subscript
list was giving false positives such as for the following:

```python
typing.Union[None]
typing.Literal[None]
```

## Test Plan

`cargo test`

---------

Co-authored-by: Charlie Marsh <[email protected]>
  • Loading branch information
2 people authored and konstin committed Jul 19, 2023
1 parent 87c651f commit 7424f56
Show file tree
Hide file tree
Showing 5 changed files with 568 additions and 388 deletions.
16 changes: 16 additions & 0 deletions crates/ruff/resources/test/fixtures/ruff/RUF013_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ def f(arg: typing.Optional[int] = None):
# Union


def f(arg: Union[None] = None):
pass


def f(arg: Union[None, int] = None):
pass

Expand All @@ -68,6 +72,10 @@ def f(arg: Union = None): # RUF013
pass


def f(arg: Union[int] = None): # RUF013
pass


def f(arg: Union[int, str] = None): # RUF013
pass

Expand Down Expand Up @@ -106,10 +114,18 @@ def f(arg: None = None):
pass


def f(arg: Literal[None] = None):
pass


def f(arg: Literal[1, 2, None, 3] = None):
pass


def f(arg: Literal[1] = None): # RUF013
pass


def f(arg: Literal[1, "foo"] = None): # RUF013
pass

Expand Down
Loading

0 comments on commit 7424f56

Please sign in to comment.