1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
# mypy: ignore-errors
# https://github.com/python/mypy/issues/16607
"""
Testing features that either are 3.12+ only or render slightly different on 3.12.
"""
from __future__ import annotations
import typing
from typing import NamedTuple
# Testing the new Python 3.12 `type` statement.
type MyType = int
"""A custom Python 3.12 type."""
foo: MyType
"""A custom type instance."""
type MyTypeWithoutDocstring = int
MyTypeClassic: typing.TypeAlias = int
"""A "classic" typing.TypeAlias."""
# Testing a typing.NamedTuple
# we do not care very much about collections.namedtuple,
# the typing version is superior for documentation and a drop-in replacement.
class NamedTupleExample(NamedTuple):
"""
An example for a typing.NamedTuple.
"""
name: str
"""Name of our example tuple."""
id: int = 3
|