4 ms·
Python Negatypes (2021)
- hwayne 4y agoFun followup: turns out that `__subclasshook__` interacts with the new pattern matching. I'm writing a short piece on that now.
- isitmadeofglass 4y ago> How is this useful? No idea. I love endeavors like this. It’s an interesting feature and a fun read, who cares if it’s useful or not.
- btown 4y ago`__subclasshook__` is super useful if you're trying to pass a mock when unit testing code that (despite this not being a best practice) checks its inputs with isinstance and checks for a class that is far more complex to instantiate than would be wise for your test. I can't say I've ever seen it used outside of testing code before, though.
- smitty1e 4y ago> How is this useful? It seems as though we're talking about a `filter` at the type level. Whatever properties we might like to prove about a random set of types would seem more easily expressed in a positive, rather than negative, mode.