From 4a83d8bc2fd87549b8f129045342eaa671ca8bd6 Mon Sep 17 00:00:00 2001 From: Yasser Tahiri Date: Tue, 9 Jan 2024 01:59:26 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20imports=20and?= =?UTF-8?q?=20caching=20in=20color.py=20and=20country.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pydantic_extra_types/color.py | 8 +------- pydantic_extra_types/country.py | 12 ++++++------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/pydantic_extra_types/color.py b/pydantic_extra_types/color.py index 8010df87..5229adbc 100644 --- a/pydantic_extra_types/color.py +++ b/pydantic_extra_types/color.py @@ -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 diff --git a/pydantic_extra_types/country.py b/pydantic_extra_types/country.py index a32fa60a..270b9bea 100644 --- a/pydantic_extra_types/country.py +++ b/pydantic_extra_types/country.py @@ -28,7 +28,7 @@ class CountryInfo: official_name: str -@lru_cache() +@lru_cache def _countries() -> list[CountryInfo]: return [ CountryInfo( @@ -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}