Title: Theory / Unimportant / CS / Programming / Python / Lib / typing
Tags: computer_to_instruction automatedNewLineAfterCommaSpace declaration syntactical_sugar todo_declaration

Typ: Any
Meaning: A type annotation representing every types. Can be used instead of any other type anywhere
Page: https://www.python.org/dev/peps/pep-0484/
Language: Python
Intuition: Default anotation for any argument and type returns

Instruction: type(None)
Page: https://www.python.org/dev/peps/pep-0484/
Language: Python
Context: Type hint
Abbreviation: None

Question: How to make type alias in Python ?
Answer: Simple variable assignments
Page: https://www.python.org/dev/peps/pep-0484/
Context: Type hint

Typ: Callable[foo,bar]
Meaning: Functions with arguments of type foo returning bar
Page: https://www.python.org/dev/peps/pep-0484/
Language: Python
Context: Type hint

Typ: Callable[...,bar]
Meaning: Function returing an object of type bar where arguments' type are not given
Page: https://www.python.org/dev/peps/pep-0484/
Language: Python
Context: Type hint

Instruction: TypeVar(foo)
Page: https://www.python.org/dev/peps/pep-0484/
Language: Python
Context: Type hint
Returns: A new variable representing some abstract type whose name is foo
Assuming: foo is also the name of the variable to which the expression is assigned
Name: Type variable

Instruction: TypeVar(foo,bar_1,...,bar_n)
Page: https://www.python.org/dev/peps/pep-0484/
Language: Python
Context: Type hint
Returns: A new variable representing some abstract type whose name is foo whose possible values are some bar_i
Assuming: same assumption that TypeVar(foo). And n>1

Instruction: NewType('foo',bar)
Page: https://www.python.org/dev/peps/pep-3107/
Language: Python
Context: Typing
Returns: A new type, whose name is foo and considered to be a subtype of bar

Instruction: foo(bar)
Page: https://www.python.org/dev/peps/pep-3107/
Language: Python
Context: Typing
Returns: bar but of type foo
Variables: foo a new type created by NewType('foo',bar)
Assuming: plop of type bar

Name: A generic type
Definition: A type parametrized by other types
Page: https://docs.python.org/3/library/typing.html

Typ: Generic[T]
Meaning: A type parametrized by another type
Page: https://docs.python.org/3/library/typing.html
Language: Python

Instruction: class Foo(
  Generic[Bar_1,
  ...,
  Bar_n]
)
Page: https://docs.python.org/3/library/typing.html
Meaning: States T is a type in the class,
  and that the class Foo is parametrized by the types Bar_1,
  ..., Bar_n
Language: Python
Assuming: Each Bar_i distinct

Typ: Foo
Meaning: Foo[Any]
Page: https://docs.python.org/3/library/typing.html
Language: Python
Context: Generic type
Variables: Foo a Generic[T] type

Typ: object
Meaning: Any object, on which no operation can be applied
Page: https://docs.python.org/3/library/typing.html
Language: Python

Question: Difference between Any and object
Answer: Everything is valid when some variable's type is Any. Nothing is valid when it's object
Page: https://docs.python.org/3/library/typing.html
Context: Python

Instruction: isinstance(x,T)
Page: https://docs.python.org/3/library/typing.html
Effect: Raise a TypeError
Language: Python
Context: Typing
Variables: T a TypeVar
x an object

Instruction: (contra/co)variant = True
Page: https://docs.python.org/3/library/typing.html
Language: Python
Context: TypeVar('T')
Returns: State that the type is contra/co variant

Instruction: Type[foo]
Page: https://docs.python.org/3/library/typing.html
Language: Python
Returns: Covariant type, which is the type of foo
Variables: foo an expression
Extra: Note thus that it returns a type of type
Assuming: foo is classes, Any, type variables, and unions of any of these types

Typ: Generator[foo,bar,plop].
Meaning: Type of generator Yelding foo, sending type bar and returning type plop
Page: https://docs.python.org/3/library/typing.html
Language: Python
Extra: Covariant type, which is the type of foo

Instruction: cast(foo, bar)
Page: https://docs.python.org/3/library/typing.html
Language: Python
Context: Typing
Returns: foo considered to be of type bar

Instruction: get_type_hints(foo)
Page: https://docs.python.org/3/library/typing.html
Language: Python
Context: Typing
Returns: Return a dictionary containing type hints for a function, method, module or class object foo

Instruction: @overload
def process(foo:bar) -> plop:
    ... (here are some actual "...")
Page: https://docs.python.org/3/library/typing.html
Effect: Introduce one typing for the function process, for the typechecker. The method is not actually defined here
Language: Python
Context: Typing
Returns: A method raising NotImplementedError when called

Instruction: @no_type_check
Page: https://docs.python.org/3/library/typing.html
Effect: Decorator stating not to type check the following function or class
Language: Python
Context: Typing

Instruction: @no_type_check_decorator
Page: https://docs.python.org/3/library/typing.html
Effect: Decorator for decorator, adding no_type_check to them
Language: Python
Context: Typing

Typ: NoReturn
Meaning: States that the method never returns (not even implicitly)
Page: https://docs.python.org/3/library/typing.html
Language: Python
Context: Typing

Typ: Union[foo_1, ..., foo_n]  ( or foo_1 | ... | foo_n since Python 3.10)
Meaning: Any of the type foo_i
Page: https://docs.python.org/3/library/typing.html
Language: Python
Context: Typing

Typ: Optional[X]
Meaning: Union[X,None]
Page: https://docs.python.org/3/library/typing.html
Language: Python
Context: Typing

Typ: Tuple[foo_1, ..., foo_n]
Meaning: A tuple with n elements, the i-th of type foo_i
Page: https://docs.python.org/3/library/typing.html
Language: Python
Context: Typing

Typ: ClassVar[foo]
Meaning: Type of class variable whose type is foo
Page: https://docs.python.org/3/library/typing.html
Language: Python
Context: Typing

Typ: AnyStr
Meaning: TypeVar('AnyStr', str, bytes).
Page: https://docs.python.org/3/library/typing.html
Language: Python
Context: Typing

Instruction: TYPE_CHECKING
Page: https://docs.python.org/3/library/typing.html
Language: Python
Context: Typing
Returns: True during type checking, False at run time

Typ: Generator[YeldType, SentdType, ReturnType]
Meaning: A generator that yeld YeldType, receive SendType and returns ReturnType
Page: https://docs.python.org/3/library/typing.html

Instruction: cast(foo, bar)
Page: https://docs.python.org/3/library/typing.html
Language: Python
Context: Typing
Returns: foo
Typ: bar