PEP 622: Don't use "ADT" for "algebraic data types"
ADT already means Abstract Data Types (a different concept).
This commit is contained in:
parent
33788eb974
commit
a39035a22e
10
pep-0622.rst
10
pep-0622.rst
|
@ -781,14 +781,14 @@ every class is matchable and therefore is subject to the checks specified
|
||||||
above.
|
above.
|
||||||
|
|
||||||
|
|
||||||
Sealed classes as ADTs
|
Sealed classes as algebraic data types
|
||||||
----------------------
|
--------------------------------------
|
||||||
|
|
||||||
Quite often it is desirable to apply exhaustiveness to a set of classes without
|
Quite often it is desirable to apply exhaustiveness to a set of classes without
|
||||||
defining ad-hoc union types, which is itself fragile if a class is missing in
|
defining ad-hoc union types, which is itself fragile if a class is missing in
|
||||||
the union definition. A design pattern where a group of record-like classes is
|
the union definition. A design pattern where a group of record-like classes is
|
||||||
combined into a union is popular in other languages that support pattern
|
combined into a union is popular in other languages that support pattern
|
||||||
matching and is known under a name of algebraic data types [2]_ or ADTs.
|
matching and is known under a name of algebraic data types [2]_.
|
||||||
|
|
||||||
We propose to add a special decorator class ``@sealed`` to the ``typing``
|
We propose to add a special decorator class ``@sealed`` to the ``typing``
|
||||||
module [6]_, that will have no effect at runtime, but will indicate to static
|
module [6]_, that will have no effect at runtime, but will indicate to static
|
||||||
|
@ -797,8 +797,8 @@ be defined in the same module as the base class.
|
||||||
|
|
||||||
The idea is that since all subclasses are known, the type checker can treat
|
The idea is that since all subclasses are known, the type checker can treat
|
||||||
the sealed base class as a union of all its subclasses. Together with
|
the sealed base class as a union of all its subclasses. Together with
|
||||||
dataclasses this allows a clean and safe support of ADTs in Python. Consider
|
dataclasses this allows a clean and safe support of algebraic data types
|
||||||
this example::
|
in Python. Consider this example::
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import sealed
|
from typing import sealed
|
||||||
|
|
Loading…
Reference in New Issue