Skip to content

Commit 2b1129d

Browse files
[pycountry] Add stubs for 24.6.1 (closes #15001)
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
1 parent 5aea297 commit 2b1129d

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

stubs/pycountry/METADATA.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
version = "24.6.*"
2+
upstream_repository = "https://github.com/pycountry/pycountry"
3+
4+
[tool.stubtest]
5+
skip = false
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import pycountry.db
2+
3+
LOCALES_DIR: str
4+
DATABASE_DIR: str
5+
__version__: str | None
6+
7+
def resource_filename(package_or_requirement: str, resource_name: str) -> str: ...
8+
def get_version(distribution_name: str) -> str | None: ...
9+
def remove_accents(input_str: str) -> str: ...
10+
11+
class ExistingCountries(pycountry.db.Database):
12+
data_class: type
13+
root_key: str
14+
def search_fuzzy(self, query: str) -> list[pycountry.db.Country]: ...
15+
16+
class HistoricCountries(ExistingCountries):
17+
data_class: type
18+
root_key: str
19+
20+
class Scripts(pycountry.db.Database):
21+
data_class: str
22+
root_key: str
23+
24+
class Currencies(pycountry.db.Database):
25+
data_class: str
26+
root_key: str
27+
28+
class Languages(pycountry.db.Database):
29+
no_index: list[str]
30+
data_class: str
31+
root_key: str
32+
33+
class LanguageFamilies(pycountry.db.Database):
34+
data_class: str
35+
root_key: str
36+
37+
class SubdivisionHierarchy(pycountry.db.Data):
38+
country_code: str
39+
parent_code: str | None
40+
def __init__(self, **kw: str) -> None: ...
41+
@property
42+
def country(self) -> pycountry.db.Country | None: ...
43+
@property
44+
def parent(self) -> SubdivisionHierarchy | None: ...
45+
46+
class Subdivisions(pycountry.db.Database):
47+
data_class: type
48+
no_index: list[str]
49+
root_key: str
50+
def get(
51+
self, *, default: SubdivisionHierarchy | None = ..., **kw: str
52+
) -> SubdivisionHierarchy | None | list[SubdivisionHierarchy]: ...
53+
def match(self, query: str) -> list[SubdivisionHierarchy]: ...
54+
def partial_match(self, query: str) -> list[SubdivisionHierarchy]: ...
55+
def search_fuzzy(self, query: str) -> list[SubdivisionHierarchy]: ...
56+
57+
countries: ExistingCountries
58+
subdivisions: Subdivisions
59+
historic_countries: HistoricCountries
60+
currencies: Currencies
61+
languages: Languages
62+
language_families: LanguageFamilies
63+
scripts: Scripts

stubs/pycountry/pycountry/db.pyi

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import logging
2+
from collections.abc import Callable, Iterator
3+
from typing import Any, TypeVar
4+
5+
logger: logging.Logger
6+
7+
_F = TypeVar("_F", bound=Callable[..., Any])
8+
9+
class Data:
10+
def __init__(self, **fields: str) -> None: ...
11+
def __getattr__(self, key: str) -> str: ...
12+
def __setattr__(self, key: str, value: str) -> None: ...
13+
def __dir__(self) -> list[str]: ...
14+
def __iter__(self) -> Iterator[tuple[str, str]]: ...
15+
16+
class Country(Data): ...
17+
class Subdivision(Data): ...
18+
19+
def lazy_load(f: _F) -> _F: ...
20+
21+
class Database:
22+
data_class: type | str
23+
root_key: str | None
24+
no_index: list[str]
25+
filename: str
26+
factory: type
27+
objects: list[Data]
28+
index_names: set[str]
29+
indices: dict[str, dict[str, Data]]
30+
31+
def __init__(self, filename: str) -> None: ...
32+
@lazy_load
33+
def add_entry(self, **kw: str) -> None: ...
34+
@lazy_load
35+
def remove_entry(self, **kw: Any) -> None: ...
36+
@lazy_load
37+
def __iter__(self) -> Iterator[Data]: ...
38+
@lazy_load
39+
def __len__(self) -> int: ...
40+
@lazy_load
41+
def get(self, *, default: Data | None = ..., **kw: Any) -> Data | None: ...
42+
@lazy_load
43+
def lookup(self, value: str) -> Data: ...

0 commit comments

Comments
 (0)