Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add stubs for assertpy#11916

Merged
JelleZijlstra merged 4 commits intopython:mainpython/typeshed:mainfrom
rafaph:assertpyCopy head branch name to clipboard
May 15, 2024
Merged

Add stubs for assertpy#11916
JelleZijlstra merged 4 commits intopython:mainpython/typeshed:mainfrom
rafaph:assertpyCopy head branch name to clipboard

Conversation

@rafaph
Copy link
Contributor

@rafaph rafaph commented May 15, 2024

No description provided.

@github-actions

This comment has been minimized.

@rafaph
Copy link
Contributor Author

rafaph commented May 15, 2024

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 ignore_missing_imports in the pyproject.toml file every time I start a new project.

So, I hope this makes someone besides me a little happier while using this library. 😄

@github-actions

This comment has been minimized.

Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.


__tracebackhide__: bool

Iterable: TypeAlias = _Iterable[Any]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a complicated way of importing Iterable, it doesn't need to be in the stub. (Also in some other files.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

from typing_extensions import Self, TypeAlias

Iterable: TypeAlias = _Iterable[Any]
str_types: tuple[type[str]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would omit this too, it's just Python 2/3 compatibility stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I removed str_types, Iterable, and one xrange!

Iterable: TypeAlias = _Iterable[Any]

class DynamicMixin:
def __getattr__(self, attr: str) -> Self: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Suggested change
def __getattr__(self, attr: str) -> Self: ...
def __getattr__(self, attr: str) -> Callable[..., Self]: ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I missed that, fixed!

@rafaph
Copy link
Contributor Author

rafaph commented May 15, 2024

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.

Thanks, I had one minor problem with the exception.pyi and fixed it! :)

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra JelleZijlstra merged commit 5079dc1 into python:main May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.