Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pydecimal() - min_value and max_value should support Decimal, along with float #2041

Open
sshishov opened this issue May 5, 2024 · 4 comments

Comments

@sshishov
Copy link
Contributor

sshishov commented May 5, 2024

  • Faker version: 25.0.1
  • OS: MacOS 14.4.1 (23E224)

After migrating to version 25+, profiding default value as Decimal for min or max values causes violation

Steps to reproduce

amount=fake.pydecimal(min_value=Decimal(1), max_value=Decimal(100000)),

Expected behavior

The should not be any error observed. The rationale - a lot of software using Decimal from the box for all calculations, in the constants etc to rely on precise double calculation. Therefore I think that it should support Decimal from the box, especially if it is returning Decimal itself.

Actual behavior

Produces this mypy error:

 error: Argument "min_value" to "pydecimal" of "Faker" has incompatible type "Decimal"; expected "float | None"  [arg-type]
@sshishov sshishov changed the title pydecimal - min_value and max_value should support Decimal, along with float pydecimal() - min_value and max_value should support Decimal, along with float May 5, 2024
@stefan6419846
Copy link
Contributor

This is a typing issue, no "real" bug. Feel free to provide a PR to update the corresponding type hint and regenerate the typing stubs.

@sshishov
Copy link
Contributor Author

sshishov commented May 5, 2024

@stefan6419846 how I can report typing issues? Because we are havily using faker, and we are requiring strict typing, that's why I have noticed these errors...

If you will give me a way to report typing issues, then I will report there.

@stefan6419846
Copy link
Contributor

It is indeed correct to report this here, but your initial report sounded like an implementation bug and not a type hint issue.

@parsariyahi
Copy link
Contributor

If we want to fix that, we can add more annotation in code

    def pydecimal(
        self,
        left_digits: Optional[int] = None,
        right_digits: Optional[int] = None,
        positive: bool = False,
        min_value: Optional[Union[float, int, Decimal]] = None,
        max_value: Optional[Union[float, int, Decimal]] = None,
    ) -> Decimal:

but I think a problem is, we can have another types of numbers that are subclass of int or something like this,
how we can handle that in here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants