Skip to content

Commit

Permalink
drop python<=3.7 support (#2030)
Browse files Browse the repository at this point in the history
  • Loading branch information
kloczek committed Apr 29, 2024
1 parent 2049e02 commit d6c0814
Show file tree
Hide file tree
Showing 19 changed files with 33 additions and 51 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
38 changes: 19 additions & 19 deletions faker/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from collections import OrderedDict
from random import Random
from typing import Any, Callable, Dict, List, Optional, Pattern, Sequence, Tuple, TypeVar, Union
from typing import Any, Callable, Pattern, Sequence, TypeVar

from .config import DEFAULT_LOCALE
from .exceptions import UniquenessException
Expand All @@ -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
2 changes: 0 additions & 2 deletions faker/proxy.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import datetime

from collections import OrderedDict
from decimal import Decimal
from enum import Enum
from json import encoder
from typing import (
Any,
Expand All @@ -18,7 +17,6 @@ from typing import (
Set,
Tuple,
Type,
TypeVar,
Union,
)
from uuid import UUID
Expand Down
1 change: 0 additions & 1 deletion faker/sphinx/autodoc.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding=utf-8
import ast
import traceback

Expand Down
7 changes: 3 additions & 4 deletions faker/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
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


class CreditCard:
Expand Down
4 changes: 0 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Developers",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
Expand Down Expand Up @@ -73,6 +70,5 @@
python_requires=">=3.8",
install_requires=[
"python-dateutil>=2.4",
"typing-extensions>=3.10.0.1;python_version<='3.8'",
],
)
2 changes: 1 addition & 1 deletion tests/providers/test_enum.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding=utf-8
import inspect

from unittest import mock
Expand Down
4 changes: 1 addition & 3 deletions tests/sphinx/test_validator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding=utf-8
import sys

Check failure on line 1 in tests/sphinx/test_validator.py

View workflow job for this annotation

GitHub Actions / flake8

'sys' imported but unused

from unittest import mock
Expand Down Expand Up @@ -100,8 +99,7 @@ def test_allowed_literal_types(self):

def test_prohibited_literal_types(self):
commands = ["variable.method(...)"]
if sys.version_info[0] == 3 and sys.version_info[1] >= 6:
commands.append('f"{variable}"')
commands.append('f"{variable}"')

for command in commands:
validator = SampleCodeValidator(command)
Expand Down

0 comments on commit d6c0814

Please sign in to comment.