python / cpython

The Python programming language
https://www.python.org/
Other
61.06k stars 29.49k forks source link

functools.partial missing __weakref__ descriptor? #87507

Open df79943f-4aee-4531-a00d-c6b12816eb70 opened 3 years ago

df79943f-4aee-4531-a00d-c6b12816eb70 commented 3 years ago
BPO 43341
Nosy @rhettinger, @mr-nfamous

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: ```python assignee = None closed_at = None created_at = labels = ['type-bug', '3.8'] title = 'functools.partial missing __weakref__ descriptor?' updated_at = user = 'https://github.com/mr-nfamous' ``` bugs.python.org fields: ```python activity = actor = 'rhettinger' assignee = 'none' closed = False closed_date = None closer = None components = [] creation = creator = 'bup' dependencies = [] files = [] hgrepos = [] issue_num = 43341 keywords = [] message_count = 1.0 messages = ['387781'] nosy_count = 2.0 nosy_names = ['rhettinger', 'bup'] pr_nums = [] priority = 'normal' resolution = None stage = None status = 'open' superseder = None type = 'behavior' url = 'https://bugs.python.org/issue43341' versions = ['Python 3.8'] ```

df79943f-4aee-4531-a00d-c6b12816eb70 commented 3 years ago

The only way to lookup weak references to functools.partial objects is with weakref.getweakrefs. I don't know if it's normal for extension types that define tpweaklistoffset to not add a \_weakref descriptor, but I figured at the very least a subtype specifying "__weakref" in its __slots could get one. Instead, it fails with the partially true TypeError: __weakref slot disallowed: either we already got one, or __itemsize__ != 0.