Skip to content

Commit

Permalink
docs: fix (#25)
Browse files Browse the repository at this point in the history
Signed-off-by: nstarman <nstarman@users.noreply.github.com>
  • Loading branch information
nstarman authored Aug 28, 2024
1 parent 5dd81d1 commit 25de4bd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,12 @@ few useful converter functions. If you need more, check out `attrs`!

```python
from attrs import define, field
from dataclassish.converters import optional, ifnotisinstance
from dataclassish.converters import Optional, Unless


@define
class Class1:
attr: int | None = field(default=None, converter=optional(int))
attr: int | None = field(default=None, converter=Optional(int))


obj = Class1()
Expand All @@ -250,7 +250,7 @@ print(obj.attr)

@define
class Class2:
attr: float | int = field(converter=ifnotisinstance((int,), converter=float))
attr: float | int = field(converter=Unless(int, converter=float))


obj = Class2(1)
Expand Down
13 changes: 0 additions & 13 deletions src/dataclassish/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,6 @@
includes: ``attrs`` and ``equinox``. This module provides a few useful converter
functions. If you need more, check out ``attrs``!
A quick rant of why rejecting PEP 712 was a bad idea. A core design guideline
for Python is Postel's Law: "be conservative in what you send, be liberal in
what you accept" (https://en.wikipedia.org/wiki/Robustness_principle). Currently
dataclasses are conservative in what they "send" (i.e., the types of their
attributes when accessed from an instance of a dataclass). The problem is that
without converters dataclasses are ALSO conservative in what they "accept" (how
they can be initialized), since they require that the types of the attributes
match the types of the fields. The onus of data structuring is forced on the
user. This is a violation of Postel's Law. Without PEP 712's converter support
the only way to be liberal in the what dataclasses accept is to write a custom
``__init__`` method, in which case why are we even using a dataclass?! The
rejection of PEP 712 directly contradicts a core design principle of Python.
"""
# ruff:noqa: N801
# pylint: disable=C0103
Expand Down

0 comments on commit 25de4bd

Please sign in to comment.