-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[pycountry] Add stubs for pycountry 24.6.1 (closes #15001) #15002
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
Conversation
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
donbarbos
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I’m not sure how relevant adding these stubs to typeshed would be, but I just wanted to point out a few small nits.
stubs/pycountry/METADATA.toml
Outdated
| version = "24.6.*" | ||
| upstream_repository = "https://github.com/pycountry/pycountry" | ||
|
|
||
| [tool.stubtest] | ||
| skip = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use alignment in METADATA.toml, so let's keep the consistent style, and defaults value of skip is false
| version = "24.6.*" | |
| upstream_repository = "https://github.com/pycountry/pycountry" | |
| [tool.stubtest] | |
| skip = false | |
| version = "24.6.*" | |
| upstream_repository = "https://github.com/pycountry/pycountry" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
stubs/pycountry/pycountry/db.pyi
Outdated
| class Country(Data): ... | ||
| class Subdivision(Data): ... | ||
|
|
||
| def lazy_load(f: _F) -> _F: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A more suitable way here is to use Callable with ParamSpec and TypeVar inside:
| def lazy_load(f: _F) -> _F: ... | |
| def lazy_load(f: Callable[_P, _R]) -> Callable[_P, _R]: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
stubs/pycountry/pycountry/db.pyi
Outdated
| @lazy_load | ||
| def __len__(self) -> int: ... | ||
| @lazy_load | ||
| def get(self, *, default: Data | None = ..., **kw: Any) -> Data | None: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a check inside that kw should be str, so I don't see any reason to set it to Any.
| def get(self, *, default: Data | None = ..., **kw: Any) -> Data | None: ... | |
| def get(self, *, default: Data | None = ..., **kw: str) -> Data | None: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
stubs/pycountry/pycountry/db.pyi
Outdated
| @lazy_load | ||
| def add_entry(self, **kw: str) -> None: ... | ||
| @lazy_load | ||
| def remove_entry(self, **kw: Any) -> None: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this kw are passed on to self.get, so the situation here is similar, see below
| def remove_entry(self, **kw: Any) -> None: ... | |
| def remove_entry(self, **kw: str) -> None: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
stubs/pycountry/pycountry/db.pyi
Outdated
|
|
||
| logger: logging.Logger | ||
|
|
||
| _F = TypeVar("_F", bound=Callable[..., Any]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see below
| _F = TypeVar("_F", bound=Callable[..., Any]) | |
| _P = ParamSpec("_P") | |
| _R = TypeVar("_R") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I imported ParamSpec from typing_extensions for Python 3.9 - is that correct?
Add type stubs for pycountry 24.6.*, providing type annotations for: - Database classes (ExistingCountries, HistoricCountries, Currencies, Languages, Scripts, etc.) - SubdivisionHierarchy and Subdivisions classes - Core data classes (Country, Subdivision, Data) - Module-level functions and constants
2e5f9f8 to
ada29a1
Compare
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
srittau
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Add type stubs for pycountry 24.6.*, providing type annotations for:
The pycountry upstream is marked with py.typed but code base not yet fully typed. Already have related MR for upstream pycountry to complete type hints; but due to slower pycountry release; added the type hints here for completeness.