Skip to content

pyfloat - error on combining positive and max_value #2300

@FadingFog

Description

@FadingFog
  • Faker version: 40.1.0
  • OS: Windows 11
  • Python 3.13.2

Error when combining positive=True and max_value that is lower than ~0.5 (it seems to depend on the generated value).

from faker import faker

faker = Faker()
faker.pyfloat(positive=True, max_value=0.1)

Error:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\User\PycharmProjects\test\.venv\Lib\site-packages\faker\providers\python\__init__.py", line 239, in pyfloat
    result = result - (result - max_value + self.generator.random.uniform(0, max_value - min_value))
                                                                             ~~~~~~~~~~^~~~~~~~~~~
TypeError: unsupported operand type(s) for -: 'float' and 'NoneType

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions