Check for mapping types using collections.abc
mainWhen writing code that needs to check if an object is a dictionary-like mapping or a bidirectional mapping, do not use isinstance(obj, dict). Instead, use the Abstract Base Classes (ABCs) from collections.abc to ensure compatibility with all mapping types (including bidict and ChainMap).
- Use
collections.abc.Mappingto check if an object is a read-only mapping. - Use
collections.abc.MutableMappingto check if an object is a mutable mapping. - Use
bidict.BidirectionalMappingto check if an object is a bidirectional mapping.