-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
stubgenc.py does not generate correct lines for staticmethods #13574
Comments
For overloaded static methods the class A:
@staticmethod
@overload
def some_static_method(a: A1, b: B1): ...
@overload
def some_static_method(a: A2, b: B2): ...
@overload
def some_static_method(a: A3, b: B3): ... Passing an additional decorator string argument to class A:
@overload
@staticmethod
def some_static_method(a: A1, b: B1): ...
@overload
@staticmethod
def some_static_method(a: A2, b: B2): ...
@overload
@staticmethod
def some_static_method(a: A3, b: B3): ... |
I created #14934 to fix this issue, but he pull request seems to have gone cold. I don't get any response from the reviewers and I can't merge it since I don't have the necessary permissions. How should I proceed? I would like to have this bug fixed. |
Fixes #13574 This PR fixes the generation of type hints for static methods of pybind11 classes. The code changes are based on the suggestions in #13574. The fix introduces an additional check if the property under inspection is of type `staticmethod`. If it is, the type information is read from the staticmethod's `__func__` attribute, instead of the staticmethod instance itself. I added a test for C++ classes with static methods bound using pybind11. Both, an overloaded and a non-overloaded static method are tested.
Bug Report
When I use stubgen to generate stub file for a pybind11 module
where
pybind11::class_ klass
is bound to C++class A
the result line is like:
which should be like:
The issue here is related to a pybind11 discussion: [https://github.com/pybind/pybind11/issues/2403].
which says "a static method of class Foo, Foo.dict['f_static'] points to the static method decorator around the function object instead, not the function object itself"
So, I temporarily fixed this issue for my own project by appending a staticmethod checker right after the
is_c_classmethod
in file stubgenc.py:The result turns out correct with my pybind11 code. But I guess it may not work for other conditions?
The text was updated successfully, but these errors were encountered: