On Feb 17, 2020, at 04:09, ananthan ananthan <[email protected]>
wrote:
>
> At last found what I was trying to convey.
>
> A new class >>BinaryInt(n: Integer *, bits,signed=False)
>
> It should accept float values.(now >> "bin(5.8)".. will raise an error).
Just float, or any type convertible to int?
Whatever you decide, it should be easy to implement. For example, in your
__new__ method:
# ...
# if you only want float, wrap this in an isinstance check
intvalue = int(value) # maybe also a try/except/raise around this?
if intvalue != value:
raise ValueError(f"{cls.__name__} cannot be constructed from
non-integral value {value}")
self = int.__new__(cls, intvalue)
# ...
But just throwing out features you want doesn’t help much. You need to do all
the work to design everything, and then implement it. There are a dozen
questions along the way (including all the ones I‘ve thought of, but probably
more that I haven’t), and building the code is the best way to find all of
them, and to have enough context to answer each one. Once you have a complete
implementation, you can make the case for why this should be in the stdlib.
And, if it gets rejected, you still have it for your own use, and can publish
it on PyPI for others. (And maybe, if it gets a lot more use than other people
expected, you can propose it to be added to the stdlib again in the future.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/3C4HMIBEWESAJ7O6VPDHHYTHWZNFOZ7D/
Code of Conduct: http://python.org/psf/codeofconduct/