mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 22:01:18 +00:00
[ty] Format conflicting types as an enumeration (#18956)
## Summary Format conflicting declared types as ``` `str`, `int` and `bytes` ``` Thanks to @AlexWaygood for the initial draft. @dcreager, looking forward to your one-character follow-up PR.
This commit is contained in:
parent
c0beb3412f
commit
86fd9b634e
5 changed files with 90 additions and 83 deletions
|
@ -16,7 +16,7 @@ def _(flag: bool):
|
|||
else:
|
||||
x: int
|
||||
|
||||
x = 1 # error: [conflicting-declarations] "Conflicting declared types for `x`: str, int"
|
||||
x = 1 # error: [conflicting-declarations] "Conflicting declared types for `x`: `str` and `int`"
|
||||
```
|
||||
|
||||
## Incompatible declarations for 2 (out of 3) types
|
||||
|
@ -29,7 +29,7 @@ def _(flag1: bool, flag2: bool):
|
|||
x: int
|
||||
|
||||
# Here, the declared type for `x` is `int | str | Unknown`.
|
||||
x = 1 # error: [conflicting-declarations] "Conflicting declared types for `x`: str, int"
|
||||
x = 1 # error: [conflicting-declarations] "Conflicting declared types for `x`: `str` and `int`"
|
||||
```
|
||||
|
||||
## Incompatible declarations with repeated types
|
||||
|
@ -47,7 +47,7 @@ def _(flag1: bool, flag2: bool, flag3: bool, flag4: bool):
|
|||
else:
|
||||
x: bytes
|
||||
|
||||
x = "a" # error: [conflicting-declarations] "Conflicting declared types for `x`: str, int, bytes"
|
||||
x = "a" # error: [conflicting-declarations] "Conflicting declared types for `x`: `str`, `int` and `bytes`"
|
||||
```
|
||||
|
||||
## Incompatible declarations with bad assignment
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue