Skip to content

Commit 63b498d

Browse files
[pycountry] Add stubs for pycountry (#15002)
1 parent 1ef6a70 commit 63b498d

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

stubs/pycountry/METADATA.toml

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

0 commit comments

Comments
 (0)