You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Don't enable GC for classes that don't add new fields #67914
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2015-04-13.18:10:31.603>created_at=<Date2015-03-20.20:25:57.755>labels= ['interpreter-core', 'performance']
title="Don't enable GC for classes that don't add new fields"updated_at=<Date2015-04-13.19:30:52.528>user='https://github.com/eltoder'
As far as I can tell, if a new class does not add any new fields, and its base class doesn't use GC, there's no reason to enable GC for the new class.
This is useful for creating lightweight wrappers around classes implemented in C.
May be we should forbid assigning the __class__ attribute of basic builtin
types (especially internable, such as int, str, bytes, tuple, bool, NoneType).
Activity
eltoder commentedon Mar 20, 2015
As far as I can tell, if a new class does not add any new fields, and its base class doesn't use GC, there's no reason to enable GC for the new class.
This is useful for creating lightweight wrappers around classes implemented in C.
serhiy-storchaka commentedon Mar 20, 2015
It looks weird.
eltoder commentedon Mar 20, 2015
Agreed, but this is not new. This works without my change:
pitrou commentedon Mar 20, 2015
I wasn't aware of that :-o
serhiy-storchaka commentedon Mar 20, 2015
May be we should forbid assigning the __class__ attribute of basic builtin
types (especially internable, such as int, str, bytes, tuple, bool, NoneType).
eltoder commentedon Mar 20, 2015
Actually, this is rather new -- new in 3.5. The check was relaxed in bpo-22986: https://hg.python.org/cpython/rev/c0d25de5919e
Previously only heap types allowed re-assigning __class__.
python-dev commentedon Apr 13, 2015
New changeset a60b7945ef87 by Antoine Pitrou in branch 'default':
Issue bpo-23726: Don't enable GC for user subclasses of non-GC types that don't add any new fields.
https://hg.python.org/cpython/rev/a60b7945ef87
pitrou commentedon Apr 13, 2015
I've pushed the patch, thank you!
eltoder commentedon Apr 13, 2015
Thank you!
Benjamin, Nathaniel, any opinion if we should restrict reassigning __class__ for types like tuple, int and str, where some/many instances are cached?
njsmith commentedon Apr 13, 2015
Yes, it probably would be a good idea to disallow assigning __class__ for immutable types.
eltoder commentedon Apr 13, 2015
Agreed. There's a small problem with that, as far as I know. Nothing on type declares that it is immutable.