Skip to content

Commit

Permalink
Merge pull request #195 from Atem18/194-isocodeslanguagesgetname=span…
Browse files Browse the repository at this point in the history
…ish-is

Change condition to retrieve element via get
  • Loading branch information
Atem Serem authored Aug 29, 2023
2 parents ff0b909 + f032130 commit 00dafa7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
10 changes: 5 additions & 5 deletions isocodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 {}
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]" }]
license = { file = "LICENSE" }
Expand All @@ -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"]
Expand Down
12 changes: 2 additions & 10 deletions tests/test_general.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 00dafa7

Please sign in to comment.