Conversation
Don't want the diversion to unexpectedly complete early
| The minor performance hit is acceptable vs. having to maintain `WeakDiversion` instances for each extension. | ||
| """ | ||
|
|
||
| class WeakDiversion(cls, Exception): |
There was a problem hiding this comment.
one weakness with dynamically creating this class is that it is unique every time make_weak is called.
given:
>>> def f():
... class C(Exception): ...
... return C
>>> A = f()
>>> B = f()
# If the same instance is used:
>>> try:
... raise A()
... except A:
... pass
>>>
# if a different instance is used:
>>> try:
... raise A()
... except B:
... pass
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
__main__.f.<locals>.C
You can get around this by caching the result of this function (though be careful to access the value on the class itself)
>>> class E(Exception):
... weakened = None
... @classmethod
... def make_weak(cls):
... if cls.weakened is None:
... class Weakened(cls, Exception): ...
... cls.weakened = Weakened
... return cls.weakened
>>> A = E.make_weak()
>>> B = E.make_weak()
>>> try:
... raise A()
... except B:
... pass
>>>
| def make_weak(cls, *args: Any, **kwargs: Any) -> Diversion: | ||
| """Make weak variant of the diversion class. | ||
|
|
||
| By dynamically forming it provides support for generic extensions of the base diversions. |
There was a problem hiding this comment.
ok hear me out instead of doing this you have a metaclass that generates this exactly once. It's so much machinery for about no payoff
There was a problem hiding this comment.
while we're on the subject of dumb ways to implement this, how about the 3-arg form of type?
Weakened = type('Weakened', (Diversion, Exception,), {})
| The minor performance hit is acceptable vs. having to maintain `WeakDiversion` instances for each extension. | ||
| """ | ||
|
|
||
| class WeakDiversion(cls, Exception): |
There was a problem hiding this comment.
creating it inline also means that the classname is a little goofy. You can fix that by assigning to both __name__ and __qualname__ of the class
| - name: Build | ||
| run: python -m build | ||
|
|
||
| publish-and-publish: |
There was a problem hiding this comment.
you could also make this a separate WF and trigger it only on main
There was a problem hiding this comment.
Ya, I think I like how this logically groups it though, keeps the related things together
0.2.0
except Exception: