Skip to content

Commit b6dd2d3

Browse files
committed
rewrite rationale
1 parent e95e9f4 commit b6dd2d3

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

peps/pep-0834.rst

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -512,19 +512,18 @@ defaults.
512512
Rationale
513513
=========
514514

515-
Class builders make the class-transforming nature of dataclasses, enums, and
516-
typing constructs visible at the start of the statement. This is easier to
517-
read and teach than a decorator or base class that changes class construction
518-
after the reader has already parsed the statement as an ordinary class.
519-
520-
The builder protocol deliberately reuses class-body machinery instead of
521-
introducing a general macro or block system. This keeps the feature close to
522-
existing class semantics while still allowing builders to return non-class
523-
objects when appropriate.
524-
525-
Only bare names are accepted as builders. This keeps the syntax compact and
526-
avoids ambiguous statement prefixes such as ``pkg.builder C:``. Users can
527-
bind a local name when they want to use a builder imported from another module.
515+
Python has various constructs that are somewhat like classes, but behave
516+
subtly (or not so subtly!) differently. This PEP proposes a generic, flexible
517+
mechanism for defining such constructs.
518+
519+
An alternative could be to add specific syntax for some or all of the constructs
520+
for which this PEP proposes to use class builders. For example, ``protocol`` could
521+
be made a soft keyword, allowing protocols to be written as proposed in this PEP,
522+
but without an import and without a more powerful new language feature.
523+
524+
However, this would unduly privilege the standard library. There are use
525+
cases in third-party frameworks that could be helped by builder syntax, including
526+
alternative dataclass-like frameworks, ORMs, or DSLs.
528527

529528

530529
Backwards Compatibility

0 commit comments

Comments
 (0)