use-types-from-typing

For Python < 3.9 only, require typing.Dict, typing.List, typing.Set, and typing.Tuple annotations instead of builtin generic aliases such as dict[str, str].

Message

For Python < 3.9, builtins.{builtin_type} is used as a type annotation but the type system doesn’t recognize it as a valid type. Use typing.{correct_type} instead.

Valid examples

def function(list: List[str]) -> None:
    pass
def function() -> None:
    thing: Dict[str, str] = {}
def function() -> None:
    thing: Tuple[str]
Show more
from typing import Dict, List
def function() -> bool:
        return Dict == List
from typing import List as list
from graphene import List

def function(a: list[int]) -> List[int]:
        return []
from builtins import list as ListType

LT = ListType

class LT:
    def __class_getitem__(cls, item):
        return cls

def func(value: LT[str]) -> None:
    pass

Invalid examples

from typing import List
def whatever(list: list[str]) -> None:
    pass

Suggested fix

from typing import List
def whatever(list: List[str]) -> None:
    pass
Show more
def function(list: list[str]) -> None:
    pass
def func() -> None:
    thing: dict[str, str] = {}
def func() -> None:
    thing: tuple[str]
from typing import Dict
def func() -> None:
    thing: dict[str, str] = {}

Suggested fix

from typing import Dict
def func() -> None:
    thing: Dict[str, str] = {}
from builtins import list as ListType

def func(value: ListType[str]) -> None:
    pass
from builtins import list as ListType

LT = ListType

def func(value: LT[str]) -> None:
    pass
from builtins import list as ListType

LT = OtherLT = ListType

def func(value: OtherLT[str]) -> None:
    pass