Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-90562: Improve zero argument support for super() in dataclasses when slots=True #124692

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

Open
wants to merge 18 commits into
base: main
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix breaking out from outer loop when handling property
  • Loading branch information
Bobronium committed Sep 27, 2024
commit e91c28bcafcd2efc26be3c1822b40920b71cc6c7
3 changes: 3 additions & 0 deletions 3 Lib/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,9 @@ def _add_slots(cls, is_frozen, weakref_slot, defined_fields):
f = inspect.unwrap(f)
if _update_func_cell_for__class__(f, cls, newcls):
break
ericvsmith marked this conversation as resolved.
Show resolved Hide resolved
else:
continue
break
elif hasattr(member, "__get__") and not inspect.ismemberdescriptor(
member
):
Expand Down
46 changes: 46 additions & 0 deletions 46 Lib/test/test_dataclasses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5141,6 +5141,52 @@ def foo(self, value):

self.assertEqual(A().foo, "bar")

def test_pure_functions_preferred_to_custom_descriptors(self):
class CustomDescriptor:
def __init__(self, f):
self._wrapper = partial(f, value="bar")

def __get__(self, instance, owner):
return self._wrapper(instance)

def __dir__(self):
raise RuntimeError("Never should be accessed")

class B:
def foo(self, value):
return value

with self.assertRaises(RuntimeError) as context:
@dataclass(slots=True)
class A(B):
@CustomDescriptor
def foo(self, value): ...

self.assertEqual(context.exception.args, ("Never should be accessed",))

@dataclass(slots=True)
class A(B):
@CustomDescriptor
def foo(self, value):
return super().foo(value)

@property
def bar(self):
return super()

self.assertEqual(A().foo, "bar")

@dataclass(slots=True)
class A(B):
@CustomDescriptor
def foo(self, value):
return super().foo(value)

def bar(self):
return super()

self.assertEqual(A().foo, "bar")

def test_custom_too_nested_descriptor(self):
class UnnecessaryNestedWrapper:
def __init__(self, wrapper):
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.