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

[stubgen] align is_classmethod with is_staticmethod #18657

Open
wants to merge 2 commits into
base: master
Choose a base branch
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
Next Next commit
align is_classmethod with is_staticmethod
Make classmethod detection more in line with staticmethod detection.
This correctly handles a few additional cases: for example, callables
created via PyCMethod_New and friends will no longer be classified as
classmethods.
  • Loading branch information
ericmarkmartin committed Feb 22, 2025
commit 3d7e030f09e8ff9e0bfc974b360b4e93aa55ad33
10 changes: 5 additions & 5 deletions mypy/stubgenc.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,12 +553,12 @@ def is_method(self, class_info: ClassInfo, name: str, obj: object) -> bool:

def is_classmethod(self, class_info: ClassInfo, name: str, obj: object) -> bool:
if self.is_c_module:
return inspect.isbuiltin(obj) or type(obj).__name__ in (
"classmethod",
"classmethod_descriptor",
)
raw_lookup: Mapping[str, Any] = getattr(class_info.cls, "__dict__") # noqa: B009
raw_value = raw_lookup.get(name, obj)
classmethod_descriptor = type(int.__dict__["from_bytes"])
return isinstance(raw_value, classmethod) or isinstance(raw_value, classmethod_descriptor)
else:
return inspect.ismethod(obj)
return isinstance(inspect.getattr_static(class_info.cls, name), classmethod)

def is_staticmethod(self, class_info: ClassInfo | None, name: str, obj: object) -> bool:
if class_info is None:
Expand Down