DEV Community

Super Kai (Kazuya Ito)
Super Kai (Kazuya Ito)

Posted on • Edited on

Glossary in Python (1)

Buy Me a Coffee

assignment statement (asgstmt)

  • is the code to assgin values to untyped variables:
    • Multiple values can be assigned to multiple variables at once.
    • It's required to assign one or more values to one or more variables with =.

annotated assignment statement (annasgstmt)

  • is the code to assgin a value to a typed variable:
    • Only a single value can be assigned to a single variable at once.
    • It's optional to assign a single value to a single variable with =.
  • is a kind of an asgstmt.

bytecode compiler (BC)

  • is the component of PyCo to check the syntax of Python code, then to compile the Python code into bytecode at ctime.

compile time (ctime)

  • is the time when BC is compiling Python code into bytecode.

dynamic type

  • is the implicit type always inferred by VM at rtime.
  • can also be called runtime type but I use dynamic type because it's completely opposite to static type, which is more intuitive.

garbage collector (GC)

  • is the component of VM to free the memory of no longer-used objects.
  • works in the background at rtime.

generic type

  • is the type besed on a generic class, function or type alias to reuse them within a type hint.
  • is list, tuple, set, dict, Callable, etc.
  • basically makes [] required in strict mode in mypy.
  • basically makes [] optional in unstrict mode in mypy.

generics

  • is the feature to create the generic class, function or type alias to reuse them as a generic type within a type hint.

item

  • is the number, character, byte or key-value pair in an iterable:
    • E.g. [0, 1, 2] has 3 items 0, 1 and 2.
    • E.g. 'ABC' and b'ABC' have 3 items A, B and C each.
    • E.g. {'A':0, 'B':1, 'C':2} has 3 items 'A':0, 'B':1 and 'C':2.
  • can also be called element or value but I use item because element is long and value is too broad, confusing with the value of key-value pair.

non-union type

  • means a single type in talking about types because it isn't inferred as Union by PyCo at ptime:
    • PyCo at ptime is more important program than type checkers at pptime.

parameter specification (ParamSpec)

  • is the code to specify the types and order of function parameters.

parameter specification operator (ParamSpec operator)

  • is ** to receive a parameter specification(ParamSpec):
    • E.g. class Cls[**P]: ....
    • E.g. def func[**P](x: Callable[P, None]) -> None: ....
    • E.g. type TA[**P] = Callable[P, None].
  • only exists to receive a ParamSpec but not to unpack a ParamSpec.
  • isn't an unpack operator.

pre-Python core time (pptime)

  • is the time before ptime to check Python code with type checkers, linters, etc.
  • can also be called static analysis time but I use pre-Python core time because the abbrs. pptime and ptime are a good combination.

Python core time (ptime)

  • is the total time of ctime and rtime.

Python core (PyCo)

  • is the Python's engine which consists of BC and VM to repeat the cycle BC ➝ VM.
  • can also be called Python interpreter(PyIn) but I use Python core because the interpreter of Python interpreter isn't very distinct from the compiler of bytecode compiler, which is confusing.

runtime (rtime)

  • is the time when VM is running the bytecode compiled by BC.
  • can also be called execution time, running time, etc but I use runtime because it's shorter.

special typing form (STF)

  • is the type to do something special within a type hint.
  • is Union, Optional, Concatenate, Literal, etc:
  • basically makes [] required whether strict mode or not in mypy.
  • can also be called special form as used in Python doc but I use special typing form because it's more descriptive.

static type

  • is the explicitly written optional type hint checked, or a type inferred by type checkers at pptime.
  • can also be called pptime type but I use static type because it's completely opposite to dynamic type, which is more intuitive.

strict mode

  • means checking strictly.

subtype

  • is the child type which has parent types as supertypes by extending them:
    • Basically, a subtype is accepted by its supertypes but its supertypes aren't accepted by the subtype. For example, bool is a subtype of int so bool is accepted by int but int isn't accepted by bool.
  • can also be called child type but I use subtype because it's shorter.

subtype-like type

  • is the type which isn't actually a subtype of other type but the type is accepted by the other type as if the type is a subtype of the other type. For example, bool isn't actually a subtype of complex and float but bool is accepted by them like bool is a subtype of them so bool is a subtype-like type of complex and float.
  • can also be called child type-like type but I use subtype-like type because it's shorter.

supertype

  • is the parent type which has child types as subtypes by extended by them:
    • Basically, a supertype accepts its subtypes but its subtypes don't accept the supertype. For example, int is a supertype of bool so int accepts bool but bool doesn't accept int.
  • can also be called parent type but I use supertype because it's shorter.

supertype-like type

  • is the type which isn't actually a supertype of other type but the type accepts the other type as if the type is a supertype of the other type. For example, complex isn't actually a supertype of float, int and bool but complex accepts them like complex is a supertype of them so complex is a supertype-like type of float, int and bool.
  • can also be called parent type-like type but I use supertype-like type because it's shorter.

type checker

  • is the tool to check static types.
  • is mypy, pyright, pyrefly, ty, etc:
  • can also be called static type checker but I use type checker because it's shorter.

type hint

  • is the optional static type created by a non-union type or union type for a variable, or function parameter or return value.
  • is for type checkers so error doesn't occur with PyCo even if a type hint is wrong.
  • should be used as specific as possible.
  • can be done with ':', with one or more types and with or without '|' and '[]'.

typed

  • means having an explicit type as a type hint.

union type

  • means a set of multiple types in talking about types because it's inferred as Union by PyCo at ptime:
    • PyCo at ptime is more important program than type checkers at pptime.

unpack operator

  • is * and **:
    • *:
      • can unpack:
        • an iterable as an item, e.g. *[0, 1, 2], *{'A':0, 'B':1} and *'ABC'.
        • a tuple as a type, e.g. *tuple[int, ...] and *Ts:
          • Unpack can also unpack tuple as a type, e.g. Unpack[tuple[int, ...]] and Unpack[Ts].
      • can receive:
        • unpacked items or unpacked-like items:
          • E.g. a, *b, c = [0, 1, 2, 3, 4].
          • E.g. for a, *b, c in [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]].
          • E.g. def func(*args): ....
        • unpacked types or unpacked-like types:
          • E.g. class Cls[*Ts]: ....
          • E.g. def func[*Ts](x: Callable[[*Ts], None]) -> None: ....
          • E.g. type TA[*Ts] = Callable[[*Ts], None].
    • **:
      • can unpack a dictionary as an item:
        • E.g. **{'A':0, 'B':1}.
      • can receive:
        • unpacked items or unpacked-like items:
          • E.g. def func(**kwargs): ....
      • doesn't exist to unpack a dictionary as a type and receive unpacked items or unpacked-like types:
        • Unpack can unpack the dictionary based on TypedDict as a type, e.g. Unpack[MyTypedDict].
        • ** of **P to receive a ParamSpec is a ParamSpec operator but not an unpack operator.
  • can also be called unpacking operator, packing operator, iterable unpacking operator, dictionary unpacking operator, etc but I use unpack operator to cover all the preceding terms.

unpacked item

  • is the item which is actually unpacked from an iterable:
    • E.g. *[0, 1, 2] and **{'A':0, 'B':1}.
    • E.g. a, b, c = [0, 1, 2] and a, *b, c = [0, 1, 2, 3, 4].
    • E.g. for a, b, c in [[0, 1, 2], [3, 4, 5]]: ....
    • E.g. for a, *b, c in [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]: ....

unpacked type

  • is the type which is actually unpacked from a tuple, e.g. *tuple[int, ...], Unpack[tuple[int, ...]]] and Unpack[MyTypedDict].

unpacked object

  • is the general term for an unpacked item and unpacked type.

unpacked-like item

  • is the item which isn't actually unpacked from an iterable but behaves like an unpacked item to be received by a, b, c, a, *b, c, *args and **kwargs:
    • E.g. func(0, 1, 2), func(0), func(A=0, B=1) and func(A=0).

unpacked-like type

  • is the type which isn't actually unpacked from a tuple but behaves like an unpacked type to be received by *Ts, e.g. MyType[int, int] and MyType[int]:
    • MyType[int, int] and MyType[int] are equivalent to MyType[(int, int)] and MyType[(int,)] respectively.

unpacked-like object

  • is the general term for unpacked-like item and unpacked-like type.

unstrict mode

  • means not checking strictly.

untyped

  • means not having an explicit type as a type hint.

virtual machine (VM)

  • is the component of PyCo to run the bytecode compiled by BC.
  • contains GC.
  • infers dynamic types.

Top comments (0)