Skip to content

Commit

Permalink
ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
getzze committed Sep 25, 2024
1 parent 1b213b5 commit 0a2fcb5
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 41 deletions.
42 changes: 21 additions & 21 deletions babelfish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@
from .script import SCRIPT_MATRIX, SCRIPTS, Script

__all__ = [
"LanguageConverter",
"LanguageReverseConverter",
"LanguageEquivalenceConverter",
"CountryConverter",
"CountryReverseConverter",
"country_converters",
"COUNTRIES",
"COUNTRY_MATRIX",
"Country",
"Error",
"LanguageConvertError",
"LanguageReverseError",
"CountryConvertError",
"CountryReverseError",
"language_converters",
"LANGUAGES",
"LANGUAGE_MATRIX",
"Language",
"SCRIPTS",
"SCRIPT_MATRIX",
"Script",
'LanguageConverter',
'LanguageReverseConverter',
'LanguageEquivalenceConverter',
'CountryConverter',
'CountryReverseConverter',
'country_converters',
'COUNTRIES',
'COUNTRY_MATRIX',
'Country',
'Error',
'LanguageConvertError',
'LanguageReverseError',
'CountryConvertError',
'CountryReverseError',
'language_converters',
'LANGUAGES',
'LANGUAGE_MATRIX',
'Language',
'SCRIPTS',
'SCRIPT_MATRIX',
'Script',
]
1 change: 0 additions & 1 deletion babelfish/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def iter_entry_points(group: str, **kwargs: Any) -> EntryPoints:


class EntryPoint(_EntryPoint):

@staticmethod
def parse(eps: str) -> EntryPoint:
return EntryPoint(*map(str.strip, eps.split('=')), None) # type: ignore[call-arg]
Expand Down
9 changes: 3 additions & 6 deletions babelfish/converters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from babelfish.compat import EntryPoint, iter_entry_points
from babelfish.exceptions import LanguageConvertError, LanguageReverseError

V = TypeVar("V")
V = TypeVar('V')


# from https://github.com/kennethreitz/requests/blob/master/requests/structures.py
class CaseInsensitiveDict(Generic[V], MutableMapping[str, V]):
Expand Down Expand Up @@ -64,11 +65,7 @@ def __len__(self) -> int:

def lower_items(self) -> Iterator[tuple[str, V]]:
"""Like iteritems(), but with all lowercase keys."""
return (
(lowerkey, keyval[1])
for (lowerkey, keyval)
in self._store.items()
)
return ((lowerkey, keyval[1]) for (lowerkey, keyval) in self._store.items())

def __eq__(self, other: Any) -> bool:
if isinstance(other, Mapping):
Expand Down
1 change: 0 additions & 1 deletion babelfish/converters/alpha2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@


class Alpha2Converter(LanguageEquivalenceConverter):

CASE_SENSITIVE: ClassVar[bool] = True
SYMBOLS: ClassVar[dict[str, str]] = {}

Expand Down
1 change: 0 additions & 1 deletion babelfish/converters/alpha3b.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@


class Alpha3BConverter(LanguageEquivalenceConverter):

CASE_SENSITIVE: ClassVar[bool] = True
SYMBOLS: ClassVar[dict[str, str]] = {}

Expand Down
1 change: 0 additions & 1 deletion babelfish/converters/alpha3t.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@


class Alpha3TConverter(LanguageEquivalenceConverter):

CASE_SENSITIVE: ClassVar[bool] = True
SYMBOLS: ClassVar[dict[str, str]] = {}

Expand Down
1 change: 0 additions & 1 deletion babelfish/converters/countryname.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@


class CountryNameConverter(CountryReverseConverter):

codes: set[str]
to_name: dict[str, str]
from_name: CaseInsensitiveDict[str]
Expand Down
1 change: 0 additions & 1 deletion babelfish/converters/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@


class NameConverter(LanguageEquivalenceConverter):

CASE_SENSITIVE: ClassVar[bool] = False
SYMBOLS: ClassVar[dict[str, str]] = {}

Expand Down
3 changes: 1 addition & 2 deletions babelfish/converters/opensubtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


class OpenSubtitlesConverter(LanguageReverseConverter):

codes: set[str]
to_opensubtitles: dict[tuple[str, str | None], str]
from_opensubtitles: CaseInsensitiveDict[tuple[str, str | None]]
Expand All @@ -38,7 +37,7 @@ def __init__(self) -> None:
'zht': ('zho', 'TW'),
},
)
self.codes = (self.alpha2_converter.codes | self.alpha3b_converter.codes | set(self.from_opensubtitles.keys()))
self.codes = self.alpha2_converter.codes | self.alpha3b_converter.codes | set(self.from_opensubtitles.keys())

def convert(self, alpha3: str, country: str | None = None, script: str | None = None) -> str:
alpha3b = self.alpha3b_converter.convert(alpha3, country, script)
Expand Down
1 change: 0 additions & 1 deletion babelfish/converters/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


class ScopeConverter(LanguageConverter):

FULLNAME: ClassVar[dict[str, str]] = {'I': 'individual', 'M': 'macrolanguage', 'S': 'special'}
SYMBOLS: ClassVar[dict[str, str]] = {}

Expand Down
1 change: 0 additions & 1 deletion babelfish/converters/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


class LanguageTypeConverter(LanguageConverter):

FULLNAME: ClassVar[dict[str, str]] = {
'A': 'ancient',
'C': 'constructed',
Expand Down
1 change: 1 addition & 0 deletions babelfish/country.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CountryConverterManager(ConverterManager[CountryReverseConverter]):
entry_point: ClassVar[str] = 'babelfish.country_converters'
internal_converters: ClassVar[list[str]] = ['name = babelfish.converters.countryname:CountryNameConverter']


country_converters = CountryConverterManager()


Expand Down
2 changes: 1 addition & 1 deletion babelfish/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class LanguageConvertError(LanguageError):
"""

def __init__(self, alpha3: str, country: str| None = None, script: str| None = None) -> None:
def __init__(self, alpha3: str, country: str | None = None, script: str | None = None) -> None:
self.alpha3 = alpha3
self.country = country
self.script = script
Expand Down
5 changes: 2 additions & 3 deletions babelfish/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class LanguageConverterManager(ConverterManager[LanguageReverseConverter]):
'opensubtitles = babelfish.converters.opensubtitles:OpenSubtitlesConverter',
]


language_converters = LanguageConverterManager()


Expand Down Expand Up @@ -175,9 +176,7 @@ def __eq__(self, other: Any) -> bool:
return str(self) == other
if not isinstance(other, Language):
return False
return (self.alpha3 == other.alpha3 and
self.country == other.country and
self.script == other.script)
return self.alpha3 == other.alpha3 and self.country == other.country and self.script == other.script

def __ne__(self, other: Any) -> bool:
return not self == other
Expand Down

0 comments on commit 0a2fcb5

Please sign in to comment.