Skip to content

Commit

Permalink
Update README.md (#27)
Browse files Browse the repository at this point in the history
Signed-off-by: Nathaniel Starkman <nstarman@users.noreply.github.com>
  • Loading branch information
nstarman authored Oct 7, 2024
1 parent 0cd66fa commit b8a43e4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1 align='center'> dataclassish </h1>
<h2 align="center">Tools from <code>dataclasses</code>, extended to all of Python</h2>
<h3 align="center">Tools from <code>dataclasses</code>, extended to all of Python</h3>

Python's [`dataclasses`][dataclasses-link] provides tools for working with
objects, but only compatible `@dataclass` objects. 😢 </br> This repository is a
Expand Down Expand Up @@ -237,20 +237,22 @@ from dataclassish.converters import Optional, Unless
@define
class Class1:
attr: int | None = field(default=None, converter=Optional(int))
"""attr is converted to an int or kept as None."""


obj = Class1()
print(obj.attr)
# None

obj = Class1(a=1)
obj = Class1(a=1.0)
print(obj.attr)
# 1


@define
class Class2:
attr: float | int = field(converter=Unless(int, converter=float))
"""attr is converted to a float, unless it's an int."""


obj = Class2(1)
Expand Down

0 comments on commit b8a43e4

Please sign in to comment.