[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-11 Thread Matt del Valle
Just off the top of my head, a context manager like this would give access to the required local scope, if inspecting the execution frames isn't considered too hacky. class LocalsProcessor: def __enter__(self): self.locals_ref = inspect.currentframe().f_back.f_locals

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-11 Thread Eric V. Smith
That's basically my suggestion with dataclasses.KEYWORD_ONLY, and obviously POSITIONAL_ONLY also needs to exist. I'd be flexible on how to spell these. I'm currently thinking we need some way to switch back to "normal" (non-keyword-only, non-positional-only) fields. But I'm not done with my

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-11 Thread Paul Bryan
The syntax of what you're proposing seems fairly intuitive (they might not even need to be callable).  I'm struggling to envision how the context manager would acquire scope to mark fields up in the (not yet defined) dataclass, and to capture the attributes that are being defined within. On Thu,

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-11 Thread Matt del Valle
Disclaimer: I posted this earlier today but I think due to some first-post moderation related issues (that I've hopefully now gotten sorted out!) it may not have gone through. I'm posting this again just in case. If it's gone through and you've already seen it then I'm super sorry, please just

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-11 Thread Paul Bryan
If you're proposing something like this, then I think it would be compatible: class Hmm: # this: int that: float # pos: PosOnly # these: str those: str # key: KWOnly # some: list On Thu, 2021-03-11 at 14:06 -0800, Ethan Furman wrote: > On 3/11/21 10:50 AM, Paul Bryan wrote: > > On

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-11 Thread Ethan Furman
On 3/11/21 10:50 AM, Paul Bryan wrote: On Thu, 2021-03-11 at 10:45 -0800, Ethan Furman wrote: On 3/10/21 9:47 PM, Eric V. Smith wrote: I'm not sure of the best way to achieve this. Using flags to field() doesn't sound awesome, but could be made to work. Or maybe special field names or types?

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-11 Thread Paul Bryan
It's current convention (and is used by typing module and static type checkers) that string annotations evaluate to valid Python types. On Thu, 2021-03-11 at 10:45 -0800, Ethan Furman wrote: > On 3/10/21 9:47 PM, Eric V. Smith wrote: > > > I'm not sure of the best way to achieve this. Using

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-11 Thread Ethan Furman
On 3/10/21 9:47 PM, Eric V. Smith wrote: I'm not sure of the best way to achieve this. Using flags to field() doesn't sound awesome, but could be made to work. Or maybe special field names or types? I'm not crazy about that, but using special types would let you do something like:

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-11 Thread Ricky Teachey
On Thu, Mar 11, 2021 at 11:59 AM Eric V. Smith wrote: > On 3/11/2021 10:23 AM, Ricky Teachey wrote: > > On Thu, Mar 11, 2021 at 10:20 AM Paul Bryan wrote: > >> Given that @dataclass is a decorator, and otherwise you're just defining >> a class, some concerns: >> >> 1. Such proposed syntax would

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-11 Thread Eric V. Smith
On 3/11/2021 10:23 AM, Ricky Teachey wrote: On Thu, Mar 11, 2021 at 10:20 AM Paul Bryan > wrote: Given that @dataclass is a decorator, and otherwise you're just defining a class, some concerns: 1. Such proposed syntax would require a change to the language

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-11 Thread Ricky Teachey
On Thu, Mar 11, 2021 at 10:20 AM Paul Bryan wrote: > Given that @dataclass is a decorator, and otherwise you're just defining a > class, some concerns: > > 1. Such proposed syntax would require a change to the language > specification. > > 2. It would seem that / and * in a class not decorated

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-11 Thread Paul Bryan
Given that @dataclass is a decorator, and otherwise you're just defining a class, some concerns: 1. Such proposed syntax would require a change to the language specification.  2. It would seem that / and * in a class not decorated with @dataclass would be of no other utility. Paul On Thu,

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-11 Thread Ricky Teachey
On Thu, Mar 11, 2021 at 10:00 AM Ethan Furman wrote: > On 3/11/21 4:20 AM, Ricky Teachey wrote: > > > This might be a bit of an extreme step to take, but has new syntax for > this ever been discussed? Here I am using the same indicator for keyword > arguments as in a function signature, hanging

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-11 Thread Ethan Furman
On 3/11/21 4:20 AM, Ricky Teachey wrote: This might be a bit of an extreme step to take, but has new syntax for this ever been discussed? Here I am using the same indicator for keyword arguments as in a function signature, hanging on a line by itself: @dataclasses.dataclass class Comparator:

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-11 Thread Ricky Teachey
This might be a bit of an extreme step to take, but has new syntax for this ever been discussed? Here I am using the same indicator for keyword arguments as in a function signature, hanging on a line by itself: @dataclasses.dataclass class Comparator: a: Any b: Any * key:

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-11 Thread Matt del Valle
In response to Eric V. Smith, if something like what you're suggesting were to be implemented I would much rather it be done with context managers than special values, because otherwise you once again end up in a situation where it's impossible to easily subclass a dataclass (which was one of the

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-10 Thread Eric V. Smith
On 3/11/2021 1:41 AM, Paul Bryan wrote: In my experience, a dataclass with more than a few attributes makes using positional arguments unwieldy and error-prone. Agreed, just like any function or class. I would think something like @dataclass(kwonly=/bool/) with default of False would be

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-10 Thread Paul Bryan
In my experience, a dataclass with more than a few attributes makes using positional arguments unwieldy and error-prone.  I would think something like @dataclass(kwonly=bool) with default of False would be reasonably clean to implement and understand. While I appreciate supporting existing

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-10 Thread Laurie O
You're right, the goal of my PR is not to allow specifying keyword-only (or positional-only) `__init__` parameters, but rather the goal is to allow child classes to be defined with non-defaulted fields (with defaulted fields in parent classes). Keyword-only parameters is simply an

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-10 Thread Eric V. Smith
As I've said before, I'm not opposed to the feature of keyword-only arguments. I think it would be a great addition. However, the proposal from Laurie O is only for changing fields without default values following fields with default values to be keyword-only. At least that's how I understand

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-10 Thread Guido van Rossum
I've seen comments from Eric V Smith in this thread and in the PR. If he's in favor and it can be done in a backwards compatible way then he can guide you to acceptance and merging of your PR. But like all of us he has limited time. On Wed, Mar 10, 2021 at 6:15 AM Laurie O wrote: > I've had

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2021-03-10 Thread Laurie O
I've had tens of people show interest in my proposal, asking what the blocker is in acceptance. As far as I know, no Python developer has shown any interest in it. My proposal is to automatically make any non-default fields become keyword-only `__init__` parameters, with no need to have any

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2020-02-11 Thread Bartosz Marcinkowski
This has been implemented already in attrs https://www.attrs.org/en/stable/examples.html#keyword-only-attributes so I think it makes sense to just translate this to dataclasses, or treat it as a starting point for a discussion if there are any objections to 1-to-1 translation from attrs.

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2020-02-10 Thread Ricky Teachey
On Mon, Feb 10, 2020 at 9:30 AM wrote: > It's been two years since this proposal has been postponed - I would like > to revive it. > > > > > ...I propose the addition of a keyword_only flag to the > > > > @dataclass decorator that renders the __init__ method using > > > >

[Python-ideas] Re: Dataclasses, keyword args, and inheritance

2020-02-10 Thread b . marcinkowski
It's been two years since this proposal has been postponed - I would like to revive it. A quick recap (quotes edited for brevity): > > > On 23 January 2018 at 03:33, George Leslie-Waksman > > > mailto:waks...@gmail.com> wrote: > > > > > > The proposed implementation of