Skip to content

Commit

Permalink
Refactor mapping of lambda functions (#1756)
Browse files Browse the repository at this point in the history
Refactor all occurrences of `map(lambda...)` to avoid the flake8-comprehensions warning "C417 Unnecessary use of map".
  • Loading branch information
mportesdev committed Nov 28, 2022
1 parent ebdbd26 commit 79228b9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions faker/providers/geo/el_GR/__init__.py
Expand Up @@ -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")
)
2 changes: 1 addition & 1 deletion faker/providers/internet/__init__.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion faker/providers/internet/el_GR/__init__.py
Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions tests/providers/test_person.py
Expand Up @@ -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):
Expand Down

0 comments on commit 79228b9

Please sign in to comment.