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年05月29日 20:09 by yselivanov, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| slots_qualname.patch | xiang.zhang, 2016年11月10日 07:03 | review | ||
| slots_qualname_v2.patch | xiang.zhang, 2016年11月10日 08:34 | review | ||
| slots_special.patch | xiang.zhang, 2016年11月10日 13:48 | review | ||
| slots_special_v2.patch | xiang.zhang, 2016年11月10日 14:24 | review | ||
| slots_special_v3.patch | xiang.zhang, 2016年11月11日 13:18 | review | ||
| slots_special-v4.patch | xiang.zhang, 2016年12月05日 09:08 | review | ||
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 495 | merged | xiang.zhang, 2017年03月06日 02:42 | |
| Messages (16) | |||
|---|---|---|---|
| msg244410 - (view) | Author: Yury Selivanov (yselivanov) * (Python committer) | Date: 2015年05月29日 20:09 | |
The following code doesn't work. Would be great if we can fix it in 3.5
class Foo:
__slots__ = ('__qualname__',)
|
|||
| msg280416 - (view) | Author: Yury Selivanov (yselivanov) * (Python committer) | Date: 2016年11月09日 17:03 | |
Serhiy, maybe you know how to fix this? |
|||
| msg280418 - (view) | Author: Xiang Zhang (xiang.zhang) * (Python committer) | Date: 2016年11月09日 17:19 | |
Why should it work Yury?
__qualname__ and __doc__(if exists) are inserted into the dict when creating a class.
>>> class Foo:
... """bar"""
... __slots__ = ('__doc__',)
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: '__doc__' in __slots__ conflicts with class variable
|
|||
| msg280419 - (view) | Author: Yury Selivanov (yselivanov) * (Python committer) | Date: 2016年11月09日 17:21 | |
Because the following works without a problem:
class F:
__slots__ = ('__name__', )
f = F()
f.__name__ = 'aaaa'
This bug with __qualname__ is why _GeneratorWrapper in types.py doesn't have __slots__.
|
|||
| msg280491 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2016年11月10日 08:05 | |
What about other names set when creating a class? __module__, __class__, __classcell__? |
|||
| msg280492 - (view) | Author: Xiang Zhang (xiang.zhang) * (Python committer) | Date: 2016年11月10日 08:11 | |
I think of them but currently they don't pose a problem for practical codes like __qualname__. Maybe leaving them until there comes a real need? |
|||
| msg280505 - (view) | Author: Xiang Zhang (xiang.zhang) * (Python committer) | Date: 2016年11月10日 13:48 | |
> What about other names set when creating a class? __module__, __class__, __classcell__? __module__ remains in the class dict so I think it's a class variable. Will __class__ be set? It's inserted into the function scope. __classcell__ I think has the same situation with __qualname__. New patch also adds __classcell__. |
|||
| msg280507 - (view) | Author: Xiang Zhang (xiang.zhang) * (Python committer) | Date: 2016年11月10日 14:24 | |
slots_special_v2 fixes a bug in the previous patch. |
|||
| msg280510 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2016年11月10日 14:43 | |
__qualname__ doesn't makes much sense if it doesn't match __module__. If _GeneratorWrapper patches __qualname__, I think it should patch __module__ too. |
|||
| msg280580 - (view) | Author: Xiang Zhang (xiang.zhang) * (Python committer) | Date: 2016年11月11日 13:18 | |
v3 updates the test cases. |
|||
| msg282327 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2016年12月04日 10:25 | |
Nick, could you please look at the patch? Especially at the part about __classcell__. |
|||
| msg282332 - (view) | Author: Alyssa Coghlan (ncoghlan) * (Python committer) | Date: 2016年12月04日 12:00 | |
"__classcell__" in __slots__ doesn't really make sense, as unlike __qualname__ (which turns into a real class level attribute and can be useful to override on instances), it's only a transient entry in a class definition namespace - types.__new__ pops it automatically so it doesn't get turned into an attribute. However, consistency is a good thing, so allowing it seems reasonable. Regarding the specifics, the pending patch on issue 23722 makes it a TypeError to ever set __classcell__ to anything other than a real cell object. |
|||
| msg282401 - (view) | Author: Xiang Zhang (xiang.zhang) * (Python committer) | Date: 2016年12月05日 09:08 | |
> However, consistency is a good thing, so allowing it seems reasonable. The inconsistency also appears when "__classcell__" in slots with or without super(). v4 catches up with HEAD. |
|||
| msg288944 - (view) | Author: Yury Selivanov (yselivanov) * (Python committer) | Date: 2017年03月03日 23:11 | |
Xiang, can you make a PR? |
|||
| msg289062 - (view) | Author: Xiang Zhang (xiang.zhang) * (Python committer) | Date: 2017年03月06日 02:43 | |
PR made. :-) |
|||
| msg290274 - (view) | Author: Xiang Zhang (xiang.zhang) * (Python committer) | Date: 2017年03月24日 22:42 | |
New changeset c393ee858932f79bd6dabf31550f9a53ea90bc68 by Xiang Zhang in branch 'master': bpo-24329: allow __qualname__ and __classcell__ in __slots__ (GH-495) https://github.com/python/cpython/commit/c393ee858932f79bd6dabf31550f9a53ea90bc68 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:17 | admin | set | github: 68517 |
| 2017年03月24日 22:42:54 | xiang.zhang | set | messages: + msg290274 |
| 2017年03月08日 03:19:59 | xiang.zhang | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2017年03月06日 06:01:51 | serhiy.storchaka | set | assignee: serhiy.storchaka -> xiang.zhang |
| 2017年03月06日 02:43:42 | xiang.zhang | set | messages: + msg289062 |
| 2017年03月06日 02:42:57 | xiang.zhang | set | pull_requests: + pull_request405 |
| 2017年03月03日 23:12:12 | yselivanov | set | versions: - Python 3.5, Python 3.6 |
| 2017年03月03日 23:11:51 | yselivanov | set | messages: + msg288944 |
| 2016年12月05日 09:08:41 | xiang.zhang | set | files:
+ slots_special-v4.patch messages: + msg282401 |
| 2016年12月04日 12:04:05 | serhiy.storchaka | set | dependencies: + During metaclass.__init__, super() of the constructed class does not work |
| 2016年12月04日 12:00:57 | ncoghlan | set | messages: + msg282332 |
| 2016年12月04日 10:25:25 | serhiy.storchaka | set | nosy:
+ ncoghlan messages: + msg282327 |
| 2016年11月15日 14:08:08 | serhiy.storchaka | set | assignee: serhiy.storchaka versions: + Python 3.5 |
| 2016年11月11日 13:18:42 | xiang.zhang | set | files:
+ slots_special_v3.patch messages: + msg280580 |
| 2016年11月10日 14:43:18 | serhiy.storchaka | set | messages: + msg280510 |
| 2016年11月10日 14:32:06 | pitrou | set | nosy:
- pitrou |
| 2016年11月10日 14:24:07 | xiang.zhang | set | files:
+ slots_special_v2.patch messages: + msg280507 |
| 2016年11月10日 13:48:03 | xiang.zhang | set | files:
+ slots_special.patch messages: + msg280505 |
| 2016年11月10日 08:34:33 | xiang.zhang | set | files: + slots_qualname_v2.patch |
| 2016年11月10日 08:11:35 | xiang.zhang | set | messages: + msg280492 |
| 2016年11月10日 08:05:38 | serhiy.storchaka | set | messages: + msg280491 |
| 2016年11月10日 07:03:50 | xiang.zhang | set | files:
+ slots_qualname.patch keywords: + patch type: behavior stage: patch review |
| 2016年11月09日 17:21:29 | yselivanov | set | messages: + msg280419 |
| 2016年11月09日 17:19:06 | xiang.zhang | set | nosy:
+ xiang.zhang messages: + msg280418 |
| 2016年11月09日 17:03:04 | yselivanov | set | nosy:
+ serhiy.storchaka messages: + msg280416 versions: + Python 3.7, - Python 3.5 |
| 2015年07月21日 07:10:25 | ethan.furman | set | nosy:
- ethan.furman |
| 2015年06月01日 18:41:32 | Arfrever | set | nosy:
+ Arfrever |
| 2015年05月29日 20:50:30 | ethan.furman | set | nosy:
+ ethan.furman |
| 2015年05月29日 20:09:17 | yselivanov | create | |