File tree Expand file tree Collapse file tree 2 files changed +9
-0
lines changed
Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,12 @@ def top(cls) -> BoundedLatticeType: ...
9090class UnionMeta (LatticeMeta ):
9191 """Meta class for union types. It simplifies the union if possible."""
9292
93+ def __init__ (self , name , bases , attrs ):
94+ super ().__init__ (name , bases , attrs )
95+ if not issubclass (base := bases [0 ], BoundedLattice ):
96+ raise TypeError (f"Union must inherit from Lattice, got { bases [0 ]} " )
97+ self ._bottom = base .bottom ()
98+
9399 def __call__ (
94100 self ,
95101 typ : Iterable [LatticeType ] | LatticeType ,
@@ -125,4 +131,6 @@ def __call__(
125131 if len (params ) == 1 :
126132 return params [0 ]
127133
134+ if len (params ) == 0 :
135+ return self ._bottom
128136 return super (UnionMeta , self ).__call__ (* params )
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ class Derived(Base):
2929
3030
3131def test_union ():
32+ assert Union ({}) is BottomType ()
3233 assert PyClass (int ) | PyClass (float ) == Union (PyClass (int ), PyClass (float ))
3334 assert Union (PyClass (int ), PyClass (int )) == PyClass (int )
3435 assert Union (PyClass (int ), PyClass (float )) == Union (PyClass (int ), PyClass (float ))
You can’t perform that action at this time.
0 commit comments