Comments (10)
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.
from faker.
@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.
from faker.
It is indeed correct to report this here, but your initial report sounded like an implementation bug and not a type hint issue.
from faker.
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?
from faker.
Hi @parsariyahi , any subclass should be okay, I guess. We need to check though...
from faker.
After some research, I found something, the built-in numbers
module, this module has a class Number
which is a abstract base class for all numbers I think.
you can read it here: https://docs.python.org/3/library/numbers.html
as the docs said:
The numbers module (PEP 3141) defines a hierarchy of numeric abstract base classes which progressively define more operations. None of the types defined in this module are intended to be instantiated.
I think it's fit the needs for this annotation
from faker.
@parsariyahi using numbers.Number
seems like the right solution here. Do y ou have time to prepare a Pull Request?
from faker.
@fcurella Yes sure, you can asign this issue to me, I will prepare a PR
from faker.
turns out, Decimal
is not part of numbers.Number
.
I've tried using Union[Decimal, int, float]
, but looks like abs()
doesn't accept Decimal
, so the best I can do is to define a new type BasicNumber = [int, float]
from faker.
@fcurella Could you share a bit more about what you wrote above?
but looks like abs() doesn't accept Decimal,
abs()
says:
The argument may be an integer, a floating-point number, or an object implementing
__abs__()
.
And we have:
In [12]: Decimal.__abs__?
Signature: Decimal.__abs__(self, /)
Call signature: Decimal.__abs__(*args, **kwargs)
Type: wrapper_descriptor
String form: <slot wrapper '__abs__' of 'decimal.Decimal' objects>
Docstring: abs(self)
Plus it's clearly possible to call abs(Decimal(-1))
and get a reasonable result.
So I'm confused why you'd say it's not supported - could you help me understand 🙏🏻
from faker.
Related Issues (20)
- 25.9.1: `ruff --unsafe-fixes` shows duplicate lines in faker/providers/currency/__init__.py HOT 1
- Undocumented backwards incompatible change to `words` provider in v26.0.0 HOT 1
- Locale `hi_IN` and `en_IN` doesn't have separate male and female names
- Add Provider for vi_VN (Vietnamese) HOT 1
- fake.time_delta is always datetime.timedelta(0) HOT 4
- [Technical Selection] Will there be duplicates of IP addresses generated in bulk using Faker in a single session? HOT 2
- Intermittent RecursionError in `_safe_random_int`
- pydecaimal probability issue
- 'Generator' object has no attribute 'random_good_service_adjective_chain' HOT 1
- Update address provider for `en_IN`
- Distribution of `pydecimal` is very far from optimal HOT 1
- Some surnames for uk_UA locale have male form when name_female() is called
- Missing it_IT lorem provider
- Optionally return dates as strings in datetime provider HOT 2
- pydecimal mishandles max_value and min_value when used with left_digits/right_digits
- URNs produce the wrong result for .uri() method
- slug() - returns an empty string in some locales HOT 2
- The `zu_ZA` locale currently only has Zulu names as a provider. I'd like to add more providers related to South Africa, such as Streets, Cities, Towns, and Stadiums.
- Add provider `gj-IN` for Gujarati language
- Separate male and female names for `hi_IN` provider
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from faker.