[Python-ideas] Implicit submodule imports

Guido van Rossum guido at python.org
Fri Sep 26 06:24:42 CEST 2014


On Thu, Sep 25, 2014 at 8:32 PM, <random832 at fastmail.us> wrote:

> On Thu, Sep 25, 2014, at 21:02, Nathaniel Smith wrote:
> > and everything would just work, but I could well be missing something?
> > Is there some dragon lurking inside Python's memory management or is
> > this just an ancient overabundance of caution?
>
> Currently, this is the message you get if you attempt to reassign the
> class of a list, or an int. Is there something else that would prevent
> it? Maybe the "object layout differs" check? What if the class you are
> assigning is a legitimate subclass of the basic type?
>

IIRC the caution is for the case where a built-in type has its own
allocation policy, such as the custom free list used by float and a few
other types. The custom deallocation code is careful not to use the free
list for subclass instances. But (depending on how the free list is
implemented) if you could switch the type out for an object that's in a
custom free list, the free list could become corrupt.

There is no custom allocation for modules, and even for float I don't see
how switching types back and forth between float and a subclass could
corrupt the free list (assuming the struct size and layout constraints are
met), but it is certainly possible to have a custom allocation policy that
would be broken.

So indeed the smell of dragons is still there (they may exist in 3rd party
modules).

Perhaps we can rename HEAPTYPE to NO_CUSTOM_ALLOCATOR and set it for most
built-in types (or at least for the module type) and all will be well.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140925/f234cafe/attachment.html>


More information about the Python-ideas mailing list