[HN Gopher] Python Negatypes (2021)
___________________________________________________________________
Python Negatypes (2021)
Author : pcr910303
Score : 35 points
Date : 2022-07-09 12:26 UTC (10 hours ago)
(HTM) web link (www.hillelwayne.com)
(TXT) w3m dump (www.hillelwayne.com)
| hwayne wrote:
| Fun followup: turns out that `__subclasshook__` interacts with
| the new pattern matching. I'm writing a short piece on that now.
| smitty1e wrote:
| > 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.
| btown wrote:
| `__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.
___________________________________________________________________
(page generated 2022-07-09 23:02 UTC)