[Python-ideas] Re: Enum: determining if a value is valid

2021-03-16 Thread Marco Sulla
On Mon, 15 Mar 2021 at 20:49, Ethan Furman wrote: > Everything considered, I think I like allowing `__contains__` to verify both > names and values What about Enum.values()? > adding `default=` to the constructor for the value-based "gimme an > Enum or None" case What's the use case, apart

[Python-ideas] Re: allow initial comma

2021-03-16 Thread Richard Damon
On 3/16/21 8:22 AM, Roland Puntaier via Python-ideas wrote: > On Mon 21Mar15 15:18, Paul Bryan wrote: >> On Mon, 2021-03-15 at 11:13 +0100, Roland Puntaier via Python-ideas >> wrote: >> >>> I hesitate to call this proposal a language change. It is rather a >>> syntactic allowance, like that of the

[Python-ideas] Dataclass (or get_type_hints) wishlist item: Optional[...]

2021-03-16 Thread Paul Bryan
With some of the dataclass threads in python-ideas ongoing, I wanted to add another to the fray. There's an area where typing.get_type_hints on dataclass and __init__ produce inconsistent results. Example: @dataclass class Foo:     x: int = None >>> typing.get_type_hints(Foo) {'x': } >>>

[Python-ideas] Re: Multiple dispatch transpilation

2021-03-16 Thread David Mertz
I quite like multiple dispatch. It's odd to claim it's not OOP, since a relatively old object-oriented system, the Common Lisp Object System (CLOS) uses this as it's fundamental construct. A long time ago, I wrote about and created an example library for multimethods. Lots of other folks have

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-16 Thread Eric V. Smith
Okay, I'll do that. Thanks! Eric On 3/16/2021 6:10 PM, Guido van Rossum wrote: That's a really good question. I think that `__match_args__` should *only* contain the non-kw-only args, so that you would have to write `case C(a, c, b=b, d=d)` to match on all four attributes (but typically

[Python-ideas] Re: Multiple dispatch transpilation

2021-03-16 Thread Greg Ewing
On 17/03/21 2:54 am, Marvin van Aalst wrote: it should in principle be possible to transform the code from |Class.method|to |method(class:type)|, *before compilation*essentially allowing the same optimizations. I don't think this transformation would help with anything. If the static

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-16 Thread Guido van Rossum
That's a really good question. I think that `__match_args__` should *only* contain the non-kw-only args, so that you would have to write `case C(a, c, b=b, d=d)` to match on all four attributes (but typically you'd probably just write `case C(a, c)` -- that's about the same as `case C(a, c, b=_,

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-16 Thread Ethan Furman
On 3/16/21 1:19 PM, Brendan Barnwell wrote: On 2021-03-16 06:20, Eric V. Smith wrote: I'd like to avoid field() as much as possible. I think it's just too easy to miss what it's doing, since it has many arguments. And I'd like to make it easy to have a style that encourages all

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-16 Thread Brendan Barnwell
On 2021-03-16 06:20, Eric V. Smith wrote: I'd like to avoid field() as much as possible. I think it's just too easy to miss what it's doing, since it has many arguments. And I'd like to make it easy to have a style that encourages all non-keyword-only fields to come first. From my perspective

[Python-ideas] Re: Enum: determining if a value is valid

2021-03-16 Thread Ethan Furman
On 3/16/21 11:43 AM, Matt Wozniski wrote: On Tue, Mar 16, 2021, 2:39 PM Marco Sulla wrote: On Tue, 16 Mar 2021 at 05:38, Matt Wozniski wrote: Color.from_value(1) # returns Color.RED What if I have an alias? Aliases are different names for a single Enum member, so a by-value search is

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-16 Thread Eric V. Smith
And now I have a question for you, Guido. I'm looking at the code and I see the additions for __match_args__. Is there any bad interaction between this proposal and the match statement? I assume __match_args__ be the re-ordered arguments to __init__, but I want to make sure. So this:

[Python-ideas] Re: Enum: determining if a value is valid

2021-03-16 Thread Matt Wozniski
That's a problem with any attempt to find an enum member by value, since values aren't guaranteed to be unique. With either proposal, we'd just need to pick one - probably the one that appears first in the class dict. On Tue, Mar 16, 2021, 2:39 PM Marco Sulla wrote: > On Tue, 16 Mar 2021 at

[Python-ideas] Re: Enum: determining if a value is valid

2021-03-16 Thread Marco Sulla
On Tue, 16 Mar 2021 at 05:38, Matt Wozniski wrote: > Color.from_value(1) # returns Color.RED What if I have an alias? ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-16 Thread Eric V. Smith
On 3/16/2021 12:16 PM, Ricky Teachey wrote: On Tue, Mar 16, 2021 at 11:59 AM Eric V. Smith > wrote: On 3/16/2021 10:06 AM, Ricky Teachey wrote: ... I think I prefer it, too. But what about using something like `mark=dataclasses.KW_ONLY` rather than

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-16 Thread Eric V. Smith
This was discussed on this thread: https://mail.python.org/archives/list/python-ideas@python.org/message/I3RKK4VINZUBCGF2TBJN6HTDV3PVUEUQ/ Ultimately the thing that doomed it for me was the repr that would be required for eval(repr(dataclass_instance)) to work. You'd have to drop the field

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-16 Thread Abdulla Al Kathiri
Why don’t we also add dataclasses.POS_ONLY as well? Anything before it is positional argument. @dataclasses.dataclass class LotsOfFields: x: Any y: Any z: Any _:dataclasses.POS_ONLY a: Any __: dataclasses.KW_ONLY b: Any = 0 c: Any = 'foo' d: Any e: Any

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-16 Thread Ricky Teachey
On Tue, Mar 16, 2021 at 11:59 AM Eric V. Smith wrote: > On 3/16/2021 10:06 AM, Ricky Teachey wrote: > > ... > I think I prefer it, too. But what about using something like > `mark=dataclasses.KW_ONLY` rather than `kw_only=True` (in the field > constructor)? So it isn't an on/off switch and as to

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-16 Thread Eric V. Smith
On 3/16/2021 10:06 AM, Ricky Teachey wrote: On Tue, Mar 16, 2021 at 10:03 AM Eric V. Smith > wrote: On 3/16/2021 9:48 AM, Ricky Teachey wrote: On Tue, Mar 16, 2021 at 9:23 AM Eric V. Smith mailto:e...@trueblade.com>> wrote: On 3/16/2021 7:01 AM,

[Python-ideas] Re: Multiple dispatch transpilation

2021-03-16 Thread Todd
Numba already provides as-needed JIT compilation and type annotations. I am not sure it supports multiple dispatch but if that was useful it could be added with decorators. I am not sure integrating this into the language will help much. On Tue, Mar 16, 2021, 10:07 Marvin van Aalst wrote: > Hi

[Python-ideas] Re: allow initial comma

2021-03-16 Thread Guido van Rossum
Hi Roland, Can you please give up on this particular idea? You've given it a fair try, and nobody is showing any interest in changing Python to match your proposal. That's usually a good indication that it will Never Happen, and if you keep arguing beyond that point you tend to be written off as

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-16 Thread Ricky Teachey
On Tue, Mar 16, 2021 at 10:03 AM Eric V. Smith wrote: > On 3/16/2021 9:48 AM, Ricky Teachey wrote: > > On Tue, Mar 16, 2021 at 9:23 AM Eric V. Smith wrote: > >> On 3/16/2021 7:01 AM, Simão Afonso @ Powertools Tech wrote: >> >> The problem is that if you have 1 normal parameter and 10

[Python-ideas] Multiple dispatch transpilation

2021-03-16 Thread Marvin van Aalst
Hi fellow Pythonistas! A colleague of mine recently got me involved in the Julia language and while I was really impressed by the performance, the complete lack of OOP and thus bad discoverability (not to mention all their unicode function names) for me leaves a lot to be desired. TL;DR:

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-16 Thread Eric V. Smith
On 3/16/2021 9:48 AM, Ricky Teachey wrote: On Tue, Mar 16, 2021 at 9:23 AM Eric V. Smith > wrote: On 3/16/2021 7:01 AM, Simão Afonso @ Powertools Tech wrote: >> The problem is that if you have 1 normal parameter and 10 keyword-only >> ones, you'd be

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-16 Thread Ricky Teachey
On Tue, Mar 16, 2021 at 9:23 AM Eric V. Smith wrote: > On 3/16/2021 7:01 AM, Simão Afonso @ Powertools Tech wrote: > >> The problem is that if you have 1 normal parameter and 10 keyword-only > >> ones, you'd be forced to say: > >> > >> @dataclasses.dataclass > >> class LotsOfFields: > >>

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-16 Thread Eric V. Smith
On 3/16/2021 7:01 AM, Simão Afonso @ Powertools Tech wrote: The problem is that if you have 1 normal parameter and 10 keyword-only ones, you'd be forced to say: @dataclasses.dataclass class LotsOfFields: a: Any b: Any = field(kw_only=True, default=0) c: Any =

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-16 Thread Simão Afonso
> The problem is that if you have 1 normal parameter and 10 keyword-only > ones, you'd be forced to say: > > @dataclasses.dataclass > class LotsOfFields: > a: Any > b: Any = field(kw_only=True, default=0) > c: Any = field(kw_only=True, default='foo') > d: Any =

[Python-ideas] Re: allow initial comma

2021-03-16 Thread Ned Batchelder
On 3/16/21 8:22 AM, Roland Puntaier via Python-ideas wrote: I'd like to write def my_long_function_name(     , my_long_option_2 = "some default expression 1".split()     , my_long_option_1 = "some default expression 1".split()     ):     pass Why not write this instead?: def