From 9dfa1401329c7f7fd83013b201dd7e946a62754a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Porte=C5=A1?= Date: Thu, 24 Nov 2022 11:01:05 +0100 Subject: [PATCH] Refactor mapping of lambda functions Refactor all occurrences of `map(lambda...)` to avoid the flake8-comprehensions warning "C417 Unnecessary use of map". --- faker/providers/geo/el_GR/__init__.py | 4 ++-- faker/providers/internet/__init__.py | 2 +- faker/providers/internet/el_GR/__init__.py | 2 +- tests/providers/test_person.py | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/faker/providers/geo/el_GR/__init__.py b/faker/providers/geo/el_GR/__init__.py index 14619e6d1b..733950df85 100644 --- a/faker/providers/geo/el_GR/__init__.py +++ b/faker/providers/geo/el_GR/__init__.py @@ -17,13 +17,13 @@ def local_latlng(self, *args: Any, **kwargs: Any) -> Tuple[str, str]: return str(self.local_latitude()), str(self.local_longitude()) def local_latitude(self) -> Decimal: - latitudes = list(map(lambda t: int(Decimal(t[0]) * 10000000), self.poly)) + latitudes = [int(Decimal(t[0]) * 10000000) for t in self.poly] return Decimal(str(self.generator.random.randint(min(latitudes), max(latitudes)) / 10000000)).quantize( Decimal(".000001") ) def local_longitude(self) -> Decimal: - longitudes = list(map(lambda t: int(Decimal(t[1]) * 10000000), self.poly)) + longitudes = [int(Decimal(t[1]) * 10000000) for t in self.poly] return Decimal(str(self.generator.random.randint(min(longitudes), max(longitudes)) / 10000000)).quantize( Decimal(".000001") ) diff --git a/faker/providers/internet/__init__.py b/faker/providers/internet/__init__.py index a3b8324f76..71860d69c6 100644 --- a/faker/providers/internet/__init__.py +++ b/faker/providers/internet/__init__.py @@ -592,7 +592,7 @@ def ipv6(self, network: bool = False) -> str: def mac_address(self) -> str: mac = [self.generator.random.randint(0x00, 0xFF) for _ in range(0, 6)] - return ":".join(map(lambda x: "%02x" % x, mac)) + return ":".join("%02x" % x for x in mac) def port_number(self, is_system: bool = False, is_user: bool = False, is_dynamic: bool = False) -> int: """Returns a network port number diff --git a/faker/providers/internet/el_GR/__init__.py b/faker/providers/internet/el_GR/__init__.py index ec0522582e..3f9e14fc7d 100644 --- a/faker/providers/internet/el_GR/__init__.py +++ b/faker/providers/internet/el_GR/__init__.py @@ -68,7 +68,7 @@ def replace_double_character(match): def replace_greek_character(match): matched = list(match.group(0)) - value = map(lambda l: replace[search.find(l)], matched) + value = (replace[search.find(char)] for char in matched) return "".join(value) return re.sub( diff --git a/tests/providers/test_person.py b/tests/providers/test_person.py index 8ffa4687db..a32c8e3435 100644 --- a/tests/providers/test_person.py +++ b/tests/providers/test_person.py @@ -211,22 +211,22 @@ def test_person(self): first_name_pair = self.fake.first_name_pair() assert first_name_pair assert len(first_name_pair) == 3 - assert all(map(lambda s: isinstance(s, str), first_name_pair)) + assert all(isinstance(s, str) for s in first_name_pair) first_name_male_pair = self.fake.first_name_male_pair() assert first_name_male_pair assert len(first_name_male_pair) == 3 - assert all(map(lambda s: isinstance(s, str), first_name_male_pair)) + assert all(isinstance(s, str) for s in first_name_male_pair) first_name_female_pair = self.fake.first_name_female_pair() assert first_name_female_pair assert len(first_name_female_pair) == 3 - assert all(map(lambda s: isinstance(s, str), first_name_female_pair)) + assert all(isinstance(s, str) for s in first_name_female_pair) last_name_pair = self.fake.last_name_pair() assert last_name_pair assert len(last_name_pair) == 3 - assert all(map(lambda s: isinstance(s, str), last_name_pair)) + assert all(isinstance(s, str) for s in last_name_pair) class TestNeNP(unittest.TestCase):