Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions stubs/pycountry/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version = "24.6.*"
upstream_repository = "https://github.com/pycountry/pycountry"

[tool.stubtest]
skip = false
Comment on lines +1 to +5
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"

63 changes: 63 additions & 0 deletions stubs/pycountry/pycountry/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import pycountry.db

LOCALES_DIR: str
DATABASE_DIR: str
__version__: str | None

def resource_filename(package_or_requirement: str, resource_name: str) -> str: ...
def get_version(distribution_name: str) -> str | None: ...
def remove_accents(input_str: str) -> str: ...

class ExistingCountries(pycountry.db.Database):
data_class: type
root_key: str
def search_fuzzy(self, query: str) -> list[pycountry.db.Country]: ...

class HistoricCountries(ExistingCountries):
data_class: type
root_key: str

class Scripts(pycountry.db.Database):
data_class: str
root_key: str

class Currencies(pycountry.db.Database):
data_class: str
root_key: str

class Languages(pycountry.db.Database):
no_index: list[str]
data_class: str
root_key: str

class LanguageFamilies(pycountry.db.Database):
data_class: str
root_key: str

class SubdivisionHierarchy(pycountry.db.Data):
country_code: str
parent_code: str | None
def __init__(self, **kw: str) -> None: ...
@property
def country(self) -> pycountry.db.Country | None: ...
@property
def parent(self) -> SubdivisionHierarchy | None: ...

class Subdivisions(pycountry.db.Database):
data_class: type
no_index: list[str]
root_key: str
def get( # type: ignore[override]
self, *, default: SubdivisionHierarchy | None = ..., **kw: str
) -> SubdivisionHierarchy | None | list[SubdivisionHierarchy]: ...
def match(self, query: str) -> list[SubdivisionHierarchy]: ...
def partial_match(self, query: str) -> list[SubdivisionHierarchy]: ...
def search_fuzzy(self, query: str) -> list[SubdivisionHierarchy]: ...

countries: ExistingCountries
subdivisions: Subdivisions
historic_countries: HistoricCountries
currencies: Currencies
languages: Languages
language_families: LanguageFamilies
scripts: Scripts
43 changes: 43 additions & 0 deletions stubs/pycountry/pycountry/db.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import logging
from collections.abc import Callable, Iterator
from typing import Any, TypeVar

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")


class Data:
def __init__(self, **fields: str) -> None: ...
def __getattr__(self, key: str) -> str: ...
def __setattr__(self, key: str, value: str) -> None: ...
def __dir__(self) -> list[str]: ...
def __iter__(self) -> Iterator[tuple[str, str]]: ...

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]: ...


class Database:
data_class: type | str
root_key: str | None
no_index: list[str]
filename: str
factory: type
objects: list[Data]
index_names: set[str]
indices: dict[str, dict[str, Data]]

def __init__(self, filename: str) -> 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: ...

@lazy_load
def __iter__(self) -> Iterator[Data]: ...
@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 lookup(self, value: str) -> Data: ...