Skip to content

Commit

Permalink
drop python<=3.7 support
Browse files Browse the repository at this point in the history
According to https://endoflife.date/python python 3.7 has been EOSed
at 7 Jun 2023.
Filter all code over `pyupgrade --py38-plus`.

Signed-off-by: Tomasz Kłoczko <kloczek@github.com>
  • Loading branch information
kloczek committed Apr 25, 2024
1 parent 7fa562b commit 169b435
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 40 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Expand Up @@ -44,7 +44,7 @@

# General information about the project.
project = "Faker"
copyright = "2014-{0}, Daniele Faraglia".format(datetime.now().year)
copyright = f"2014-{datetime.now().year}, Daniele Faraglia"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down
2 changes: 1 addition & 1 deletion faker/providers/address/es_CL/__init__.py
Expand Up @@ -631,7 +631,7 @@ def commune_and_region(self) -> str:
region_index = int(commune_code[0:2]) - 1
region_name = tuple(self.regions.values())[region_index]

return "{:s}, {:s}".format(commune_name, region_name)
return f"{commune_name:s}, {region_name:s}"

def road_name(self) -> str:
self.generator.set_arguments("kilometer", {"min": 1, "max": 35})
Expand Down
2 changes: 0 additions & 2 deletions faker/providers/automotive/es_CL/__init__.py
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import re

from collections import OrderedDict
Expand Down
2 changes: 0 additions & 2 deletions faker/providers/automotive/es_ES/__init__.py
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import re

from typing import Optional
Expand Down
2 changes: 1 addition & 1 deletion faker/providers/date_time/__init__.py
Expand Up @@ -70,7 +70,7 @@ class ParseError(ValueError):
("minutes", "m"),
("seconds", "s"),
]:
timedelta_pattern += r"((?P<{}>(?:\+|-)\d+?){})?".format(name, sym)
timedelta_pattern += fr"((?P<{name}>(?:\+|-)\d+?){sym})?"


class Provider(BaseProvider):
Expand Down
2 changes: 1 addition & 1 deletion faker/providers/file/__init__.py
Expand Up @@ -337,7 +337,7 @@ def unix_device(self, prefix: Optional[str] = None) -> str:
if prefix is None:
prefix = self.random_element(self.unix_device_prefixes)
suffix: str = self.random_element(string.ascii_lowercase)
path = "/dev/%s%s" % (prefix, suffix)
path = "/dev/{}{}".format(prefix, suffix)
return path

def unix_partition(self, prefix: Optional[str] = None) -> str:
Expand Down
4 changes: 2 additions & 2 deletions faker/providers/internet/el_GR/__init__.py
Expand Up @@ -46,7 +46,7 @@ def replace_accented_character(match):
return replace[search.find(matched)]
return matched

return re.sub(r"[{}]+".format(search), replace_accented_character, value)
return re.sub(fr"[{search}]+", replace_accented_character, value)


def latinize(value: str) -> str:
Expand All @@ -71,7 +71,7 @@ def replace_greek_character(match):
return "".join(value)

return re.sub(
r"[{}]+".format(search),
fr"[{search}]+",
replace_greek_character,
re.sub(
r"([ΘΧΨθχψ]+|ΟΥ|ΑΥ|ΕΥ|Ου|Αυ|Ευ|ου|αυ|ευ)",
Expand Down
4 changes: 2 additions & 2 deletions faker/providers/user_agent/__init__.py
Expand Up @@ -193,7 +193,7 @@ def chrome(
saf,
),
tmplt.format(
"Linux; {}".format(self.android_platform_token()),
f"Linux; {self.android_platform_token()}",
saf,
self.generator.random.randint(version_from, version_to),
self.generator.random.randint(build_from, build_to),
Expand Down Expand Up @@ -228,7 +228,7 @@ def firefox(self) -> str:
tmplt_mac: str = "({0}; rv:1.9.{1}.20) {2}"
tmplt_and: str = "({0}; Mobile; rv:{1}.0) Gecko/{1}.0 Firefox/{1}.0"
tmplt_ios: str = "({0}) AppleWebKit/{1} (KHTML, like Gecko) FxiOS/{2}.{3}.0 Mobile/{4} Safari/{1}"
saf: str = "{}.{}".format(self.generator.random.randint(531, 536), self.generator.random.randint(0, 2))
saf: str = f"{self.generator.random.randint(531, 536)}.{self.generator.random.randint(0, 2)}"
bld: str = self.lexify(self.numerify("##?###"), string.ascii_uppercase)
bld2: str = self.lexify(self.numerify("#?####"), string.ascii_lowercase)
platforms: ElementsType[str] = (
Expand Down
36 changes: 18 additions & 18 deletions faker/proxy.py
Expand Up @@ -30,10 +30,10 @@ class Faker:

def __init__(
self,
locale: Optional[Union[str, Sequence[str], Dict[str, Union[int, float]]]] = None,
providers: Optional[List[str]] = None,
generator: Optional[Generator] = None,
includes: Optional[List[str]] = None,
locale: str | Sequence[str] | dict[str, int | float] | None = None,
providers: list[str] | None = None,
generator: Generator | None = None,
includes: list[str] | None = None,
use_weighting: bool = True,
**config: Any,
) -> None:
Expand Down Expand Up @@ -92,7 +92,7 @@ def __init__(
self._factories = list(self._factory_map.values())

def __dir__(self):
attributes = set(super(Faker, self).__dir__())
attributes = set(super().__dir__())
for factory in self.factories:
attributes |= {attr for attr in dir(factory) if not attr.startswith("_")}
return sorted(attributes)
Expand Down Expand Up @@ -153,11 +153,11 @@ def __setstate__(self, state: Any) -> None:
self.__dict__.update(state)

@property
def unique(self) -> "UniqueProxy":
def unique(self) -> UniqueProxy:
return self._unique_proxy

@property
def optional(self) -> "OptionalProxy":
def optional(self) -> OptionalProxy:
return self._optional_proxy

def _select_factory(self, method_name: str) -> Factory:
Expand Down Expand Up @@ -188,7 +188,7 @@ def _select_factory_distribution(self, factories, weights):
def _select_factory_choice(self, factories):
return random.choice(factories)

def _map_provider_method(self, method_name: str) -> Tuple[List[Factory], Optional[List[float]]]:
def _map_provider_method(self, method_name: str) -> tuple[list[Factory], list[float] | None]:
"""
Creates a 2-tuple of factories and weights for the given provider method name
Expand Down Expand Up @@ -222,15 +222,15 @@ def _map_provider_method(self, method_name: str) -> Tuple[List[Factory], Optiona
return mapping

@classmethod
def seed(cls, seed: Optional[SeedType] = None) -> None:
def seed(cls, seed: SeedType | None = None) -> None:
"""
Hashables the shared `random.Random` object across all factories
:param seed: seed value
"""
Generator.seed(seed)

def seed_instance(self, seed: Optional[SeedType] = None) -> None:
def seed_instance(self, seed: SeedType | None = None) -> None:
"""
Creates and seeds a new `random.Random` object for each factory
Expand All @@ -239,7 +239,7 @@ def seed_instance(self, seed: Optional[SeedType] = None) -> None:
for factory in self._factories:
factory.seed_instance(seed)

def seed_locale(self, locale: str, seed: Optional[SeedType] = None) -> None:
def seed_locale(self, locale: str, seed: SeedType | None = None) -> None:
"""
Creates and seeds a new `random.Random` object for the factory of the specified locale
Expand Down Expand Up @@ -281,25 +281,25 @@ def random(self, value: Random) -> None:
raise NotImplementedError(msg)

@property
def locales(self) -> List[str]:
def locales(self) -> list[str]:
return list(self._locales)

@property
def weights(self) -> Optional[List[Union[int, float]]]:
def weights(self) -> list[int | float] | None:
return self._weights

@property
def factories(self) -> List[Generator | Faker]:
def factories(self) -> list[Generator | Faker]:
return self._factories

def items(self) -> List[Tuple[str, Generator | Faker]]:
def items(self) -> list[tuple[str, Generator | Faker]]:
return list(self._factory_map.items())


class UniqueProxy:
def __init__(self, proxy: Faker):
self._proxy = proxy
self._seen: Dict = {}
self._seen: dict = {}
self._sentinel = object()

def clear(self) -> None:
Expand Down Expand Up @@ -372,9 +372,9 @@ def __getstate__(self):
def __setstate__(self, state):
self.__dict__.update(state)

def _wrap(self, name: str, function: Callable[..., RetType]) -> Callable[..., Optional[RetType]]:
def _wrap(self, name: str, function: Callable[..., RetType]) -> Callable[..., RetType | None]:
@functools.wraps(function)
def wrapper(*args: Any, prob: float = 0.5, **kwargs: Any) -> Optional[RetType]:
def wrapper(*args: Any, prob: float = 0.5, **kwargs: Any) -> RetType | None:
if not 0 < prob <= 1.0:
raise ValueError("prob must be between 0 and 1")
return function(*args, **kwargs) if self._proxy.boolean(chance_of_getting_true=int(prob * 100)) else None
Expand Down
1 change: 0 additions & 1 deletion faker/sphinx/autodoc.py
@@ -1,4 +1,3 @@
# coding=utf-8
from faker.sphinx.docstring import ProviderMethodDocstring
from faker.sphinx.documentor import write_provider_docs

Expand Down
1 change: 0 additions & 1 deletion faker/sphinx/docstring.py
@@ -1,4 +1,3 @@
# coding=utf-8
import inspect
import logging
import re
Expand Down
3 changes: 1 addition & 2 deletions faker/sphinx/documentor.py
@@ -1,4 +1,3 @@
# coding=utf-8
import importlib
import inspect
import os
Expand Down Expand Up @@ -145,7 +144,7 @@ def _write_localized_provider_docs():
(DOCS_ROOT / "locales").mkdir(parents=True, exist_ok=True)
for locale in AVAILABLE_LOCALES:
info = _get_localized_provider_info(locale)
with (DOCS_ROOT / "locales" / "{}.rst".format(locale)).open("wb") as fh:
with (DOCS_ROOT / "locales" / f"{locale}.rst").open("wb") as fh:
_hide_edit_on_github(fh)
_write_title(fh, f"Locale {locale}")
_write_includes(fh)
Expand Down
1 change: 0 additions & 1 deletion faker/sphinx/validator.py
@@ -1,4 +1,3 @@
# coding=utf-8
import ast
import traceback

Expand Down
5 changes: 3 additions & 2 deletions faker/typing.py
Expand Up @@ -7,14 +7,15 @@
try:
from typing import List, Literal, TypeVar # type: ignore
except ImportError:
from typing_extensions import List, Literal, TypeVar # type: ignore
from typing_extensions import Literal, TypeVar # type: ignore
from typing import List

if sys.version_info >= (3, 9):
from collections import OrderedDict as OrderedDictType
elif sys.version_info >= (3, 7, 2):
from typing import OrderedDict as OrderedDictType
else:
from typing_extensions import OrderedDict as OrderedDictType # NOQA
from typing import OrderedDict as OrderedDictType # NOQA


class CreditCard:
Expand Down
2 changes: 1 addition & 1 deletion tests/providers/test_enum.py
Expand Up @@ -45,6 +45,6 @@ def test_none_raises(self, faker):
faker.enum(None)

def test_incorrect_type_raises(self, faker):
not_an_enum_type = type("NotAnEnumType")
not_an_enum_type = str
with pytest.raises(TypeError):
faker.enum(not_an_enum_type)
1 change: 0 additions & 1 deletion tests/sphinx/test_docstring.py
@@ -1,4 +1,3 @@
# coding=utf-8
import inspect

from unittest import mock
Expand Down
1 change: 0 additions & 1 deletion tests/sphinx/test_validator.py
@@ -1,4 +1,3 @@
# coding=utf-8
import sys

from unittest import mock
Expand Down

0 comments on commit 169b435

Please sign in to comment.