diff --git a/isocodes/__init__.py b/isocodes/__init__.py index d2cbdd3b..9193ee12 100644 --- a/isocodes/__init__.py +++ b/isocodes/__init__.py @@ -2,10 +2,10 @@ import json import os import sys -from typing import Dict, Generator, List +from typing import Dict, Generator, List, Optional -def get_script_dir(follow_symlinks=True): +def get_script_dir(follow_symlinks=True) -> str: if getattr(sys, "frozen", False): # py2exe, PyInstaller, cx_Freeze path = os.path.abspath(sys.executable) else: @@ -37,13 +37,13 @@ def _name_from_index(self, index: str) -> Generator[tuple, None, None]: def _sorted_by_index(self, index: str) -> List[tuple]: return sorted((element[index], element) for element in self.data) - def get(self, **kwargs) -> Dict[str, str]: - key: str = next(iter(kwargs)) + def get(self, **kwargs) -> Optional[Dict[str, str]]: try: + key: str = next(iter(kwargs)) return [ element for element in self.data - if key in element and element[key] == kwargs[key] + if key in element and kwargs[key] in element[key] ][0] except IndexError: return {} diff --git a/pyproject.toml b/pyproject.toml index 87069863..a96296b0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "isocodes" -version = "2023.06.24" +version = "2023.08.29" description = "This project provides lists of various ISO standards (e.g. country, language, language scripts, and currency names) in one place" authors = [{ name = "Atem18", email = "contact@atemlire.io" }] license = { file = "LICENSE" } @@ -23,6 +23,7 @@ classifiers = [ dependencies = [] [project.optional-dependencies] + dev = ["pre-commit >=2.17.0,<4.0.0", "ruff == 0.0.285", "mypy == 1.5.1"] doc = ["mkdocs == 1.5.2", "mkdocs-material == 9.2.3", "mkdocstrings == 0.22.0"] diff --git a/tests/test_general.py b/tests/test_general.py index 436ac4e6..6be33c82 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -1,13 +1,5 @@ -from isocodes import countries, languages, currencies - - -def test_countries(): - assert len(countries) == 249 +from isocodes import languages def test_languages(): - assert len(languages) == 487 - - -def test_currencies(): - assert len(currencies) == 181 + assert languages.get(name="Spanish")