mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-31 15:48:22 +00:00
Implement runtime-import-in-type-checking-block (TYP004) (#2146)
This commit is contained in:
parent
deff503932
commit
0758049e49
29 changed files with 364 additions and 40 deletions
5
resources/test/fixtures/flake8_type_checking/TYP004_1.py
vendored
Normal file
5
resources/test/fixtures/flake8_type_checking/TYP004_1.py
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from datetime import datetime
|
||||
x = datetime
|
8
resources/test/fixtures/flake8_type_checking/TYP004_2.py
vendored
Normal file
8
resources/test/fixtures/flake8_type_checking/TYP004_2.py
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from datetime import date
|
||||
|
||||
|
||||
def example():
|
||||
return date()
|
6
resources/test/fixtures/flake8_type_checking/TYP004_3.py
vendored
Normal file
6
resources/test/fixtures/flake8_type_checking/TYP004_3.py
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Any
|
||||
|
||||
CustomType = Any
|
11
resources/test/fixtures/flake8_type_checking/TYP004_4.py
vendored
Normal file
11
resources/test/fixtures/flake8_type_checking/TYP004_4.py
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
from typing import TYPE_CHECKING, Type
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Any
|
||||
|
||||
|
||||
def example(*args: Any, **kwargs: Any):
|
||||
return
|
||||
|
||||
|
||||
my_type: Type[Any] | Any
|
8
resources/test/fixtures/flake8_type_checking/TYP004_5.py
vendored
Normal file
8
resources/test/fixtures/flake8_type_checking/TYP004_5.py
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import List, Sequence, Set
|
||||
|
||||
|
||||
def example(a: List[int], /, b: Sequence[int], *, c: Set[int]):
|
||||
return
|
10
resources/test/fixtures/flake8_type_checking/TYP004_6.py
vendored
Normal file
10
resources/test/fixtures/flake8_type_checking/TYP004_6.py
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pandas import DataFrame
|
||||
|
||||
|
||||
def example():
|
||||
from pandas import DataFrame
|
||||
|
||||
x = DataFrame
|
10
resources/test/fixtures/flake8_type_checking/TYP004_7.py
vendored
Normal file
10
resources/test/fixtures/flake8_type_checking/TYP004_7.py
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
from __future__ import annotations
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import AsyncIterator, List
|
||||
|
||||
|
||||
class Example:
|
||||
async def example(self) -> AsyncIterator[List[str]]:
|
||||
yield 0
|
7
resources/test/fixtures/flake8_type_checking/TYP004_8.py
vendored
Normal file
7
resources/test/fixtures/flake8_type_checking/TYP004_8.py
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
from typing import TYPE_CHECKING
|
||||
from weakref import WeakKeyDictionary
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Any
|
||||
|
||||
d = WeakKeyDictionary["Any", "Any"]()
|
Loading…
Add table
Add a link
Reference in a new issue