Very strange issues with collections.Mapping

Terry Reedy tjreedy at udel.edu
Fri Jan 19 03:47:52 EST 2018


On 1/18/2018 4:37 PM, Jason Swails wrote:
> Hello!
> 
> I am running into a very perplexing issue that is very rare, but creeps up
> and is crashing my app.
> 
> The root cause of the issue comes down to the following check returning
> true:
> 
> isinstance([], collections.Mapping)

I confirmed that one *can* register 'list' as a Mapping so that the 
above returns True.  I also discovered that doing so does not change 
Mapping._abc_registry.

Have you grepped the dependencies (snipped) for '.register'?

Alternatively, the abc module doc says

"""
Changed in version 3.4: To detect calls to register(), you can use the 
get_cache_token() function.
...
abc.get_cache_token()

     Returns the current abstract base class cache token.

     The token is an opaque object (that supports equality testing) 
identifying the current version of the abstract base class cache for 
virtual subclasses. The token changes with every call to 
ABCMeta.register() on any ABC.
"""

You could call this before, between, and after all your imports, and add 
such calls to the guilty import.

-- 
Terry Jan Reedy




More information about the Python-list mailing list