-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve test cases around #16486 This PR does not change any actual mypy behavior, only hardens the stubgen tests. The specific changes are: - **dedicated test cases**: The existing pybind11 test cases originate from a pybind11 demo. They cover a specific topic involving geometry types and semi-implemented logic related to it. This somehow distracts from the aspects we are trying to test here from the mypy stubgen perspective, because it hides the actual intent of the bindings. I've simply started adding new test cases that clearly express via their name what the test case is addressing. I've kept the original demo stuff for now, so that the new cases are just an addition (overhead is negligible). - **running mypy on the generated stubs**: In general it is crucial that the output produced by the stubgen can actually be type checked by mypy (this was the regression in #18486). This wasn't covered by the CI check so far. I've added check now, which would have avoided the regression. My goal for follow up PRs would be that we can use `mypy --disallow-untyped-defs` or even `mypy --strict` on the output. - **minor directory restructuring**: So far the expected stub outputs were stored in folder names `stubgen` and `stubgen-include-docs`. This was a bit confusing, because the folder `stubgen` suggested it contains _the_ stubgen (implementation). I went for `expected_stubs_no_docs` and `expected_stubs_with_docs` to make the role of the two folders more explicit. - **minor script bugfix**: Fix a bug in `test-stubgen.sh`: The pre-delete functionality was broken, because the `*` was quoted and therefore did not match.
- Loading branch information
1 parent
1fd29ac
commit a8741d8
Showing
11 changed files
with
227 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Test stubgenc on pybind11-mypy-demo | ||
name: Test stubgenc on pybind11_fixtures | ||
|
||
on: | ||
workflow_dispatch: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
test-data/pybind11_fixtures/expected_stubs_no_docs/pybind11_fixtures/__init__.pyi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import os | ||
from . import demo as demo | ||
from typing import List, Optional, Tuple, overload | ||
|
||
class StaticMethods: | ||
def __init__(self, *args, **kwargs) -> None: ... | ||
@overload | ||
@staticmethod | ||
def overloaded_static_method(value: int) -> int: ... | ||
@overload | ||
@staticmethod | ||
def overloaded_static_method(value: float) -> float: ... | ||
@staticmethod | ||
def some_static_method(a: int, b: int) -> int: ... | ||
|
||
class TestStruct: | ||
field_readwrite: int | ||
field_readwrite_docstring: int | ||
def __init__(self, *args, **kwargs) -> None: ... | ||
@property | ||
def field_readonly(self) -> int: ... | ||
|
||
def func_incomplete_signature(*args, **kwargs): ... | ||
def func_returning_optional() -> Optional[int]: ... | ||
def func_returning_pair() -> Tuple[int, float]: ... | ||
def func_returning_path() -> os.PathLike: ... | ||
def func_returning_vector() -> List[float]: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
test-data/pybind11_fixtures/expected_stubs_with_docs/pybind11_fixtures/__init__.pyi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import os | ||
from . import demo as demo | ||
from typing import List, Optional, Tuple, overload | ||
|
||
class StaticMethods: | ||
def __init__(self, *args, **kwargs) -> None: | ||
"""Initialize self. See help(type(self)) for accurate signature.""" | ||
@overload | ||
@staticmethod | ||
def overloaded_static_method(value: int) -> int: | ||
"""overloaded_static_method(*args, **kwargs) | ||
Overloaded function. | ||
1. overloaded_static_method(value: int) -> int | ||
2. overloaded_static_method(value: float) -> float | ||
""" | ||
@overload | ||
@staticmethod | ||
def overloaded_static_method(value: float) -> float: | ||
"""overloaded_static_method(*args, **kwargs) | ||
Overloaded function. | ||
1. overloaded_static_method(value: int) -> int | ||
2. overloaded_static_method(value: float) -> float | ||
""" | ||
@staticmethod | ||
def some_static_method(a: int, b: int) -> int: | ||
"""some_static_method(a: int, b: int) -> int | ||
None | ||
""" | ||
|
||
class TestStruct: | ||
field_readwrite: int | ||
field_readwrite_docstring: int | ||
def __init__(self, *args, **kwargs) -> None: | ||
"""Initialize self. See help(type(self)) for accurate signature.""" | ||
@property | ||
def field_readonly(self) -> int: ... | ||
|
||
def func_incomplete_signature(*args, **kwargs): | ||
"""func_incomplete_signature() -> dummy_sub_namespace::HasNoBinding""" | ||
def func_returning_optional() -> Optional[int]: | ||
"""func_returning_optional() -> Optional[int]""" | ||
def func_returning_pair() -> Tuple[int, float]: | ||
"""func_returning_pair() -> Tuple[int, float]""" | ||
def func_returning_path() -> os.PathLike: | ||
"""func_returning_path() -> os.PathLike""" | ||
def func_returning_vector() -> List[float]: | ||
"""func_returning_vector() -> List[float]""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.