Skip to content

Commit f13c111

Browse files
authored
Simplify compatibility check in BaseStyle union operators (#3258)
1 parent 0d7254a commit f13c111

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

changes/3258.misc.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The logic that checks if two styles are compatible for union operators has been simplified.

travertino/src/travertino/style.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ class BaseStyle:
2222
for parameters to the constructor.
2323
"""
2424

25+
# Only "real" properties
2526
_BASE_PROPERTIES = defaultdict(set)
27+
# Includes aliases and shorthands
2628
_BASE_ALL_PROPERTIES = defaultdict(set)
2729

2830
def __init_subclass__(cls):
@@ -197,21 +199,15 @@ def __iter__(self):
197199
yield from (name for name in self._PROPERTIES if name in self)
198200

199201
def __or__(self, other):
200-
if isinstance(other, BaseStyle):
201-
if self.__class__ is not other.__class__:
202-
return NotImplemented
203-
elif not isinstance(other, Mapping):
202+
if not (type(self) is type(other) or isinstance(other, Mapping)):
204203
return NotImplemented
205204

206205
result = self.copy()
207206
result.update(**other)
208207
return result
209208

210209
def __ior__(self, other):
211-
if isinstance(other, BaseStyle):
212-
if self.__class__ is not other.__class__:
213-
return NotImplemented
214-
elif not isinstance(other, Mapping):
210+
if not (type(self) is type(other) or isinstance(other, Mapping)):
215211
return NotImplemented
216212

217213
self.update(**other)

0 commit comments

Comments
 (0)