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.

classification
Title: copyreg does not properly mangle __slots__ names
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7, Python 3.6, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: ShaneHarvey, serhiy.storchaka
Priority: normal Keywords:

Created on 2017-08-02 18:53 by ShaneHarvey, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 2989 merged python-dev, 2017-08-02 18:57
PR 3003 merged ShaneHarvey, 2017-08-04 21:06
PR 3004 merged ShaneHarvey, 2017-08-04 21:06
Messages (4)
msg299665 - (view) Author: Shane Harvey (ShaneHarvey) * Date: 2017-08-02 18:53
This line in copyreg._slotnames does not properly calculate mangled attribute names:
https://github.com/python/cpython/blob/v3.6.2/Lib/copyreg.py#L131

The problem is that it does not strip leading underscores from the class name:

>>> class _LeadingUnderscoreClassName(object):
...     __slots__ = ("__bar",)
...
>>> import copy_reg
>>> copy_reg._slotnames(_LeadingUnderscoreClassName)
['__LeadingUnderscoreClassName__bar']

The result is that copy, pickle, and anything else that relies on _slotnames() do not work on classes with leading underscores and private __slots__. This bug is present in all versions of Python.
msg299737 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-08-04 08:45
New changeset c4c9866064f03646c686d7e08b00aeb203c35c19 by Serhiy Storchaka (Shane Harvey) in branch 'master':
bpo-31107: Fix copyreg mangled slot names calculation. (#2989)
https://github.com/python/cpython/commit/c4c9866064f03646c686d7e08b00aeb203c35c19
msg299787 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-08-05 15:01
New changeset 4795ba857ef2a89e6b477285df961672106a1792 by Serhiy Storchaka (Shane Harvey) in branch '3.6':
[3.6] bpo-31107: Fix copyreg mangled slot names calculation. (GH-2989) (#3003)
https://github.com/python/cpython/commit/4795ba857ef2a89e6b477285df961672106a1792
msg299788 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-08-05 15:03
New changeset 88ffff5ddbb8692ecb2c661aa29000dbde9eff8c by Serhiy Storchaka (Shane Harvey) in branch '2.7':
[2.7] bpo-31107: Fix copyreg mangled slot names calculation. (GH-2989). (#3004)
https://github.com/python/cpython/commit/88ffff5ddbb8692ecb2c661aa29000dbde9eff8c
History
Date User Action Args
2022-04-11 14:58:49adminsetgithub: 75290
2017-08-05 15:24:03serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-08-05 15:03:03serhiy.storchakasetmessages: + msg299788
2017-08-05 15:01:13serhiy.storchakasetmessages: + msg299787
2017-08-04 21:06:56ShaneHarveysetpull_requests: + pull_request3039
2017-08-04 21:06:16ShaneHarveysetpull_requests: + pull_request3038
2017-08-04 08:45:05serhiy.storchakasetmessages: + msg299737
2017-08-02 19:35:45serhiy.storchakasetassignee: serhiy.storchaka
stage: patch review

nosy: + serhiy.storchaka
versions: + Python 3.7, - Python 3.3, Python 3.4, Python 3.5
2017-08-02 19:07:07ShaneHarveysetversions: - Python 3.7
2017-08-02 18:57:56python-devsetpull_requests: + pull_request3027
2017-08-02 18:53:14ShaneHarveycreate