Skip to content

Commit bca61b7

Browse files
committed
fix(annots): singleton-ness should be inerited
1 parent 37ef82e commit bca61b7

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

koerce/annots.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ def __new__(
723723
initable=None,
724724
hashable=None,
725725
immutable=None,
726-
singleton=False,
726+
singleton=None,
727727
allow_coercion=True,
728728
**kwargs,
729729
):
@@ -747,6 +747,7 @@ def __new__(
747747
is_initable |= spec.initable
748748
is_hashable |= spec.hashable
749749
is_immutable |= spec.immutable
750+
is_singleton |= spec.singleton
750751
signatures.append(spec.signature)
751752
attributes.update(spec.attributes)
752753

koerce/tests/test_annots.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,6 +2209,10 @@ class DataType(Annotable, singleton=True):
22092209
nullable: bool = True
22102210

22112211

2212+
class PrimitiveType(DataType):
2213+
pass
2214+
2215+
22122216
def test_singleton_basics():
22132217
one = OneAndOnly()
22142218
only = OneAndOnly()
@@ -2219,6 +2223,15 @@ def test_singleton_basics():
22192223
assert OneAndOnly.__instances__[key] is one
22202224

22212225

2226+
def test_singleton_child_is_singleton():
2227+
prim1 = PrimitiveType()
2228+
prim2 = PrimitiveType()
2229+
assert prim1 is prim2
2230+
assert len(PrimitiveType.__instances__) == 1
2231+
assert PrimitiveType.__spec__.singleton is True
2232+
assert PrimitiveType.__instances__ is DataType.__instances__
2233+
2234+
22222235
def test_singleton_lifetime() -> None:
22232236
one = OneAndOnly()
22242237
assert len(OneAndOnly.__instances__) == 1

0 commit comments

Comments
 (0)