Commit 35f402c
authored
Support type stub generation for
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.staticmethod (#14934)1 parent fbb738a commit 35f402c
File tree
4 files changed
+66
-6
lines changed- mypy
- test-data/pybind11_mypy_demo
- src
- stubgen-include-docs/pybind11_mypy_demo
- stubgen/pybind11_mypy_demo
4 files changed
+66
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
530 | 530 | | |
531 | 531 | | |
532 | 532 | | |
533 | | - | |
| 533 | + | |
534 | 534 | | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
535 | 539 | | |
536 | | - | |
537 | | - | |
538 | | - | |
| 540 | + | |
539 | 541 | | |
540 | 542 | | |
541 | 543 | | |
| |||
761 | 763 | | |
762 | 764 | | |
763 | 765 | | |
764 | | - | |
| 766 | + | |
765 | 767 | | |
766 | 768 | | |
767 | 769 | | |
| |||
793 | 795 | | |
794 | 796 | | |
795 | 797 | | |
796 | | - | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
797 | 801 | | |
798 | 802 | | |
799 | 803 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
121 | 128 | | |
122 | 129 | | |
123 | 130 | | |
| |||
166 | 173 | | |
167 | 174 | | |
168 | 175 | | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
169 | 184 | | |
170 | 185 | | |
171 | 186 | | |
| |||
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
6 | 36 | | |
7 | 37 | | |
8 | 38 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
6 | 17 | | |
7 | 18 | | |
8 | 19 | | |
| |||
0 commit comments