UseTypesFromTypingRule
Enforces the use of types from the typing
module in type annotations in place of builtins.{builtin_type}
since the type system doesn’t recognize the latter as a valid type.
Has Autofix: Yes
VALID Code Examples
# 1:
def fuction(list: List[str]) -> None:
pass
# 2:
def function() -> None:
thing: Dict[str, str] = {}
# 3:
def function() -> None:
thing: Tuple[str]
# 4:
from typing import Dict, List
def function() -> bool:
return Dict == List
# 5:
from typing import List as list
from graphene import List
def function(a: list[int]) -> List[int]:
return []
INVALID Code Examples
# 1:
from typing import List
def whatever(list: list[str]) -> None:
pass
Autofix:
---
+++
@@ -1,4 +1,4 @@
from typing import List
-def whatever(list: list[str]) -> None:
+def whatever(list: List[str]) -> None:
pass
# 2:
def function(list: list[str]) -> None:
pass
# 3:
def func() -> None:
thing: dict[str, str] = {}
# 4:
def func() -> None:
thing: tuple[str]
# 5:
from typing import Dict
def func() -> None:
thing: dict[str, str] = {}
Autofix:
---
+++
@@ -1,4 +1,4 @@
from typing import Dict
def func() -> None:
- thing: dict[str, str] = {}
+ thing: Dict[str, str] = {}