Skip to content

Commit

Permalink
♻️ Refactor imports and caching in color.py and country.py
Browse files Browse the repository at this point in the history
  • Loading branch information
yezz123 committed Jan 9, 2024
1 parent 8b229b6 commit 4a83d8b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
8 changes: 1 addition & 7 deletions pydantic_extra_types/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,8 @@

import math
import re
import sys
from colorsys import hls_to_rgb, rgb_to_hls
from typing import Any, Callable, Tuple, Union, cast

if sys.version_info >= (3, 8): # pragma: no cover
from typing import Literal
else: # pragma: no cover
from typing_extensions import Literal
from typing import Any, Callable, Literal, Tuple, Union, cast

from pydantic import GetJsonSchemaHandler
from pydantic._internal import _repr
Expand Down
12 changes: 6 additions & 6 deletions pydantic_extra_types/country.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CountryInfo:
official_name: str


@lru_cache()
@lru_cache
def _countries() -> list[CountryInfo]:
return [
CountryInfo(
Expand All @@ -42,27 +42,27 @@ def _countries() -> list[CountryInfo]:
]


@lru_cache()
@lru_cache
def _index_by_alpha2() -> dict[str, CountryInfo]:
return {country.alpha2: country for country in _countries()}


@lru_cache()
@lru_cache
def _index_by_alpha3() -> dict[str, CountryInfo]:
return {country.alpha3: country for country in _countries()}


@lru_cache()
@lru_cache
def _index_by_numeric_code() -> dict[str, CountryInfo]:
return {country.numeric_code: country for country in _countries()}


@lru_cache()
@lru_cache
def _index_by_short_name() -> dict[str, CountryInfo]:
return {country.short_name: country for country in _countries()}


@lru_cache()
@lru_cache
def _index_by_official_name() -> dict[str, CountryInfo]:
return {country.official_name: country for country in _countries() if country.official_name}

Expand Down

0 comments on commit 4a83d8b

Please sign in to comment.