Skip to content

Conversation

@jochemvangrondelle
Copy link

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

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.

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
@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 9, 2025

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

Copy link
Contributor

@donBarbos donBarbos left a 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.

Comment on lines +1 to +5
version = "24.6.*"
upstream_repository = "https://github.com/pycountry/pycountry"

[tool.stubtest]
skip = false
Copy link
Contributor

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

Suggested change
version = "24.6.*"
upstream_repository = "https://github.com/pycountry/pycountry"
[tool.stubtest]
skip = false
version = "24.6.*"
upstream_repository = "https://github.com/pycountry/pycountry"

class Country(Data): ...
class Subdivision(Data): ...

def lazy_load(f: _F) -> _F: ...
Copy link
Contributor

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:

Suggested change
def lazy_load(f: _F) -> _F: ...
def lazy_load(f: Callable[_P, _R]) -> Callable[_P, _R]: ...

@lazy_load
def __len__(self) -> int: ...
@lazy_load
def get(self, *, default: Data | None = ..., **kw: Any) -> Data | None: ...
Copy link
Contributor

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.

Suggested change
def get(self, *, default: Data | None = ..., **kw: Any) -> Data | None: ...
def get(self, *, default: Data | None = ..., **kw: str) -> Data | None: ...

@lazy_load
def add_entry(self, **kw: str) -> None: ...
@lazy_load
def remove_entry(self, **kw: Any) -> None: ...
Copy link
Contributor

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

Suggested change
def remove_entry(self, **kw: Any) -> None: ...
def remove_entry(self, **kw: str) -> None: ...


logger: logging.Logger

_F = TypeVar("_F", bound=Callable[..., Any])
Copy link
Contributor

Choose a reason for hiding this comment

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

see below

Suggested change
_F = TypeVar("_F", bound=Callable[..., Any])
_P = ParamSpec("_P")
_R = TypeVar("_R")

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