Skip to content

Commit 2b69b1b

Browse files
committed
fix: union repr setting
Signed-off-by: nstarman <nstarman@users.noreply.github.com>
1 parent 2cf148c commit 2b69b1b

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

plum/alias.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,15 @@ def _new_str(self: object) -> str:
128128
def activate_union_aliases() -> None:
129129
"""When printing `typing.Union`s, replace all aliased unions by the aliased names.
130130
This monkey patches `__repr__` and `__str__` for `typing.Union`."""
131-
_union_type.__repr__ = _new_repr
132-
_union_type.__str__ = _new_str
131+
object.__setattr__(_union_type, "__repr__", _new_repr)
132+
object.__setattr__(_union_type, "__str__", _new_str)
133133

134134

135135
def deactivate_union_aliases() -> None:
136136
"""Undo what :func:`.alias.activate` did. This restores the original `__repr__`
137137
and `__str__` for `typing.Union`."""
138-
_union_type.__repr__ = _original_repr
139-
_union_type.__str__ = _original_str
138+
object.__setattr__(_union_type, "__repr__", _original_repr)
139+
object.__setattr__(_union_type, "__str__", _original_str)
140140

141141

142142
_ALIASED_UNIONS: list = []

0 commit comments

Comments
 (0)