On 06May2019 18:47, Antoine Pitrou
On Mon, 6 May 2019 19:39:39 +0300 Serge Matveenko
wrote:On Mon, May 6, 2019 at 7:29 PM Guido van Rossum
wrote: On Mon, May 6, 2019 at 11:14 AM Serhiy Storchaka
wrote: I do not propose to change the current behavior. I propose to add new named constructors. In most cases default constructors can be used, but in cases when we use type check or different tricks to limit the type of the argument, we could use named constructors.
Current named constructors:
* dict.fromkeys() * int.from_bytes() * float.fromhex() * bytes.fromhex() * bytearray.fromhex()
Understood. My point is that we won't be able to remove the original behavior, so we'd end up with two ways to do it. :-(
With all respect, I disagree. There are ways to evolve Python such as deprecation policies which proven to be effective. There are ways to monitor current features adoption on PyPI to see whether it is safe to remove deprecated things.
The main constructors for built-in types are used so pervasively that there is no hope of actually removing such deprecated behavior.
I don't find that compelling. I for one would welcome a small suite of
unambiguous factories that can't be misused. bytes() can easily be
misused by accident, introducing bugs and requiring debug work. I'd be
very happy for my own future code to be able to take advantage of hard
to misuse constructors.
Of course we could all write tiny factories for these modes but (a) we'd
all have to write and debug them and (b) they'de all have different
spellings and signatures and (c) everyone else would not have easy
access to them (yes, PyPI notwithstanding: finding a specific module in
there can be haphazard) and (d) the bytes type is a natural place to
have these constructors/factories.
All these arguments apply to the other types too.
Cheers,
Cameron Simpson