[Python-ideas] Revisiting Immutable Mappings
Steven D'Aprano
steve at pearwood.info
Thu Oct 11 18:35:28 EDT 2018
On Thu, Oct 11, 2018 at 12:34:13PM -0700, Chris Barker via Python-ideas wrote:
> I don't care what is or isn't a subclass of what -- I don't think that's a
> Pythonic question. But I do think :
>
> issubclass(frozendict, abc.Mapping) and issubclass(frozendict, abc.Hashable)
>
> would be useful.
So you do care about what is and isn't a subclass :-)
It is 2018 and we've had isinstance and issubclass in the language since
Python 2.2 in 2002, I really wish that we could get away from the idea
that checking types is unPythonic and duck-typing is the One True Way to
do things. The old, Python 1.5 form of type-checking:
type(spam) is dict
was not so great, since it tested only for a specific type by identity.
But with ABCs and virtual subclasses and inheritance, isinstance is a
great way to check that your duck both quacks and swims, rather than
watching it sink and drown in the middle of your function :-)
--
Steve
More information about the Python-ideas
mailing list