mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00
[flake8-type-checking
] Adds implementation for TC006 (#14511)
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
b80de52592
commit
e25e7044ba
9 changed files with 295 additions and 0 deletions
62
crates/ruff_linter/resources/test/fixtures/flake8_type_checking/TC006.py
vendored
Normal file
62
crates/ruff_linter/resources/test/fixtures/flake8_type_checking/TC006.py
vendored
Normal file
|
@ -0,0 +1,62 @@
|
|||
def f():
|
||||
from typing import cast
|
||||
|
||||
cast(int, 3.0) # TC006
|
||||
|
||||
|
||||
def f():
|
||||
from typing import cast
|
||||
|
||||
cast(list[tuple[bool | float | int | str]], 3.0) # TC006
|
||||
|
||||
|
||||
def f():
|
||||
from typing import Union, cast
|
||||
|
||||
cast(list[tuple[Union[bool, float, int, str]]], 3.0) # TC006
|
||||
|
||||
|
||||
def f():
|
||||
from typing import cast
|
||||
|
||||
cast("int", 3.0) # OK
|
||||
|
||||
|
||||
def f():
|
||||
from typing import cast
|
||||
|
||||
cast("list[tuple[bool | float | int | str]]", 3.0) # OK
|
||||
|
||||
|
||||
def f():
|
||||
from typing import Union, cast
|
||||
|
||||
cast("list[tuple[Union[bool, float, int, str]]]", 3.0) # OK
|
||||
|
||||
|
||||
def f():
|
||||
from typing import cast as typecast
|
||||
|
||||
typecast(int, 3.0) # TC006
|
||||
|
||||
|
||||
def f():
|
||||
import typing
|
||||
|
||||
typing.cast(int, 3.0) # TC006
|
||||
|
||||
|
||||
def f():
|
||||
import typing as t
|
||||
|
||||
t.cast(t.Literal["3.0", '3'], 3.0) # TC006
|
||||
|
||||
|
||||
def f():
|
||||
from typing import cast
|
||||
|
||||
cast(
|
||||
int # TC006 (unsafe, because it will get rid of this comment)
|
||||
| None,
|
||||
3.0
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue