Skip to content

Commit

Permalink
fix: random sign in pyfloat when positive=False (#1954)
Browse files Browse the repository at this point in the history
  • Loading branch information
viraj-s15 authored Dec 13, 2023
1 parent efc91d5 commit 1ff3186
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions faker/providers/python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def pyfloat(
self,
left_digits=None,
right_digits=None,
positive=False,
positive=None,
min_value=None,
max_value=None,
):
Expand Down Expand Up @@ -203,7 +203,14 @@ def pyfloat(
positive,
)
else:
sign = "+" if positive else self.random_element(("+", "-"))
if positive is None:
sign = self.random_element(("+", "-"))
elif positive is True:
sign = "+"
else:
sign = "-"

Check warning on line 212 in faker/providers/python/__init__.py

View workflow job for this annotation

GitHub Actions / flake8

blank line contains whitespace

Check warning on line 213 in faker/providers/python/__init__.py

View workflow job for this annotation

GitHub Actions / flake8

blank line contains whitespace
left_number = self.random_number(left_digits)

Check failure on line 214 in faker/providers/python/__init__.py

View workflow job for this annotation

GitHub Actions / flake8

too many blank lines (2)

result = float(f"{sign}{left_number}.{self.random_number(right_digits)}")
Expand Down

0 comments on commit 1ff3186

Please sign in to comment.