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
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
Rely on inspect.getmembers_static()
  • Loading branch information
Bobronium committed Oct 5, 2024
commit 5bfea4d299566099b780f0bd17e616b157d41046
38 changes: 23 additions & 15 deletions 38 Lib/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,22 @@ def _update_func_cell_for__class__(f, oldcls, newcls):
return False


_object_members_values = {
value for name, value in
(
*inspect.getmembers_static(object),
*inspect.getmembers_static(object())
)
}


def _is_not_object_member(v):
try:
return v not in _object_members_values
except TypeError:
return True


def _find_inner_functions(obj, seen=None, depth=0):
if seen is None:
seen = set()
Expand All @@ -1253,22 +1269,14 @@ def _find_inner_functions(obj, seen=None, depth=0):
if depth > 2:
return None

for attribute in dir(obj):
try:
value = inspect.getattr_static(obj, attribute)
except AttributeError:
continue
builtin_value = inspect.getattr_static(object, attribute, None)
if value is builtin_value:
# don't waste time on builtin objects
continue
if (
# isinstance() would trigger `value.__getattribute__("__class__")`
type(value) is types.MemberDescriptorType
and type not in inspect._static_getmro(type(obj))
):
obj_is_type_instance = type in inspect._static_getmro(type(obj))
for _, value in inspect.getmembers_static(obj, _is_not_object_member):
value_type = type(value)
if value_type is types.MemberDescriptorType and not obj_is_type_instance:
value = value.__get__(obj)
if isinstance(value, types.FunctionType):
value_type = type(value)

if value_type is types.FunctionType:
yield inspect.unwrap(value)
else:
yield from _find_inner_functions(value, seen, depth)
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.