Add stubs for assertpy#11916
Add stubs for assertpy#11916JelleZijlstra merged 4 commits intopython:mainpython/typeshed:mainfrom rafaph:assertpyCopy head branch name to clipboard
assertpy#11916Conversation
This comment has been minimized.
This comment has been minimized.
|
Hi dear maintainers! I added here stubs for this amazing assertion library called assertpy. I have been using this library for a long time and it always bothers me to add So, I hope this makes someone besides me a little happier while using this library. 😄 |
This comment has been minimized.
This comment has been minimized.
JelleZijlstra
left a comment
There was a problem hiding this comment.
Thanks!
If you have a lot of existing code using this library, I'd encourage you to typecheck that code with these stubs: it may help catch some bugs in the stubs.
stubs/assertpy/assertpy/dynamic.pyi
Outdated
|
|
||
| __tracebackhide__: bool | ||
|
|
||
| Iterable: TypeAlias = _Iterable[Any] |
There was a problem hiding this comment.
This is just a complicated way of importing Iterable, it doesn't need to be in the stub. (Also in some other files.)
| from typing_extensions import Self, TypeAlias | ||
|
|
||
| Iterable: TypeAlias = _Iterable[Any] | ||
| str_types: tuple[type[str]] |
There was a problem hiding this comment.
I would omit this too, it's just Python 2/3 compatibility stuff.
There was a problem hiding this comment.
Sure, I removed str_types, Iterable, and one xrange!
stubs/assertpy/assertpy/dynamic.pyi
Outdated
| Iterable: TypeAlias = _Iterable[Any] | ||
|
|
||
| class DynamicMixin: | ||
| def __getattr__(self, attr: str) -> Self: ... |
There was a problem hiding this comment.
This is a bit unfortunate because if you use a typo on an attribute, you won't get an immediate error. Looking at the implementation, it only supports attributes starting with has_, but that can't be expressed in the type system.
However, it returns a callable, not a Self:
| def __getattr__(self, attr: str) -> Self: ... | |
| def __getattr__(self, attr: str) -> Callable[..., Self]: ... |
There was a problem hiding this comment.
Oh, I missed that, fixed!
Thanks, I had one minor problem with the |
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
No description provided.