This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2015年03月20日 20:25 by eltoder, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| class_gc.diff | eltoder, 2015年03月20日 20:25 | review | ||
| class_gc2.diff | eltoder, 2015年03月21日 18:47 | review | ||
| Messages (11) | |||
|---|---|---|---|
| msg238718 - (view) | Author: Eugene Toder (eltoder) * | Date: 2015年03月20日 20:25 | |
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. |
|||
| msg238721 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2015年03月20日 20:51 | |
>>> class UserIntSlots(int): ... __slots__ = () ... def __repr__(s): return '5' ... >>> (4).__class__ = UserIntSlots >>> 2+2 5 >>> type(2+2) <class '__main__.UserIntSlots'> It looks weird. |
|||
| msg238727 - (view) | Author: Eugene Toder (eltoder) * | Date: 2015年03月20日 22:00 | |
Agreed, but this is not new. This works without my change: >>> class Tuple(tuple): ... __slots__ = () ... def __repr__(self): return 'Imma tuple!' ... >>> ().__class__ = Tuple >>> () Imma tuple! |
|||
| msg238730 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2015年03月20日 22:10 | |
I wasn't aware of that :-o |
|||
| msg238732 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2015年03月20日 22:26 | |
May be we should forbid assigning the __class__ attribute of basic builtin types (especially internable, such as int, str, bytes, tuple, bool, NoneType). |
|||
| msg238733 - (view) | Author: Eugene Toder (eltoder) * | Date: 2015年03月20日 22:32 | |
Actually, this is rather new -- new in 3.5. The check was relaxed in #22986: https://hg.python.org/cpython/rev/c0d25de5919e Previously only heap types allowed re-assigning __class__. |
|||
| msg240690 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2015年04月13日 18:10 | |
New changeset a60b7945ef87 by Antoine Pitrou in branch 'default': Issue #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 |
|||
| msg240691 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2015年04月13日 18:10 | |
I've pushed the patch, thank you! |
|||
| msg240699 - (view) | Author: Eugene Toder (eltoder) * | Date: 2015年04月13日 18:25 | |
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? |
|||
| msg240710 - (view) | Author: Nathaniel Smith (njs) * (Python committer) | Date: 2015年04月13日 19:26 | |
Yes, it probably would be a good idea to disallow assigning __class__ for immutable types. |
|||
| msg240711 - (view) | Author: Eugene Toder (eltoder) * | Date: 2015年04月13日 19:30 | |
Agreed. There's a small problem with that, as far as I know. Nothing on type declares that it is immutable. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:14 | admin | set | github: 67914 |
| 2015年04月13日 19:30:52 | eltoder | set | messages: + msg240711 |
| 2015年04月13日 19:26:46 | njs | set | messages: + msg240710 |
| 2015年04月13日 18:25:40 | eltoder | set | nosy:
+ njs messages: + msg240699 |
| 2015年04月13日 18:10:31 | pitrou | set | status: open -> closed resolution: fixed messages: + msg240691 stage: patch review -> resolved |
| 2015年04月13日 18:10:14 | python-dev | set | nosy:
+ python-dev messages: + msg240690 |
| 2015年03月21日 18:47:31 | eltoder | set | files: + class_gc2.diff |
| 2015年03月20日 22:36:11 | serhiy.storchaka | set | nosy:
+ benjamin.peterson |
| 2015年03月20日 22:32:53 | eltoder | set | messages: + msg238733 |
| 2015年03月20日 22:26:34 | serhiy.storchaka | set | messages: + msg238732 |
| 2015年03月20日 22:10:10 | pitrou | set | messages: + msg238730 |
| 2015年03月20日 22:00:14 | eltoder | set | messages: + msg238727 |
| 2015年03月20日 20:51:00 | serhiy.storchaka | set | messages: + msg238721 |
| 2015年03月20日 20:35:47 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka stage: patch review components: + Interpreter Core versions: + Python 3.5, - Python 3.6 |
| 2015年03月20日 20:25:57 | eltoder | create | |