Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mechanism to enable __weakref__ slot on dataclass(slots=True) #91215

Closed
ariebovenberg mannequin opened this issue Mar 18, 2022 · 5 comments
Closed

Mechanism to enable __weakref__ slot on dataclass(slots=True) #91215

ariebovenberg mannequin opened this issue Mar 18, 2022 · 5 comments
Assignees
Labels
3.11 bug and security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@ariebovenberg
Copy link
Mannequin

ariebovenberg mannequin commented Mar 18, 2022

BPO 47059
Nosy @ericvsmith, @ariebovenberg

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 = None
closed_at = None
created_at = <Date 2022-03-18.18:00:50.175>
labels = ['library', '3.11']
title = 'Mechanism to enable __weakref__ slot on dataclass(slots=True)'
updated_at = <Date 2022-03-18.18:00:50.175>
user = 'https://github.com/ariebovenberg'

bugs.python.org fields:

activity = <Date 2022-03-18.18:00:50.175>
actor = 'ariebovenberg'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2022-03-18.18:00:50.175>
creator = 'ariebovenberg'
dependencies = []
files = []
hgrepos = []
issue_num = 47059
keywords = []
message_count = 1.0
messages = ['415515']
nosy_count = 2.0
nosy_names = ['eric.smith', 'ariebovenberg']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = None
url = 'https://bugs.python.org/issue47059'
versions = ['Python 3.11']

@ariebovenberg
Copy link
Mannequin Author

ariebovenberg mannequin commented Mar 18, 2022

As discussed in bpo-46382, dataclasses may want to support the __weakref__ slot.

Currently, automatically slotted dataclasses are not given a __weakref__ slot. This makes auto-slotted dataclasses incompatible with weakref.

The attrs library has chosen for the following approeach:

  • when slots are generated, a __weakref__ slot is added by default
  • this may be optionally disabled with the weakref_slot=False flag

See this discussion on why that approach was taken: python-attrs/attrs#420

The question for dataclass is: do we want to follow suit? Or perhaps make __weakref__ slot opt-in instead of opt-out?

@ariebovenberg ariebovenberg mannequin added 3.11 bug and security fixes stdlib Python modules in the Lib dir labels Mar 18, 2022
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@rhettinger
Copy link
Contributor

A weakref slot should be opt-in. No need to make everyone pay for a feature that is so rarely needed.

@ericvsmith
Copy link
Member

I agree. I would rather this be weakref_slot=True, which defaults to False.

@ericvsmith ericvsmith self-assigned this Apr 29, 2022
@ericvsmith ericvsmith added the type-feature A feature request or enhancement label Apr 29, 2022
@ericvsmith
Copy link
Member

PR #92160

@ericvsmith
Copy link
Member

#92160 was merged to 3.11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 bug and security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants