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 prototype or use cases.

I also think @dataclass(kwonly=True) is a case that should be supported, since I think the most common usage will be to make every field keyword-only. I haven't yet looked at what attrs does.

Eric

On 3/11/2021 5:12 PM, Paul Bryan wrote:
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 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? I'm not crazy about that, but using special
types would let you do something like:

@dataclasses.dataclass
class Point:
     x: int = 0
     _: dataclasses.KEYWORD_ONLY
     y: int
     z: int
     t: int = 0

Maybe something like this?

     class Hmm:
         #
         this: int
         that: float
         #
         pos: '/'
         #
         these: str
         those: str
         #
         key: '*'
         #
         some: list

     >>> Hmm.__dict__['__annotations__']
     {
         'this': <class 'int'>,
         'that': <class 'float'>,
         'pos': '/',
         'these': <class 'str'>,
         'those': <class 'str'>,
         'key': '*',
         'some': <class 'list'>,
         }

The name of 'pos' and 'key' can be convention, since the actual name
is irrelevant.  They do have to be unique, though.  ;-)

It's current convention (and is used by typing module and static type
checkers) that string annotations evaluate to valid Python types.

So make '/' and '*' be imports from dataclasses:

     from dataclasses import dataclass, PosOnly, KWOnly

--
~Ethan~
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org <mailto:python-ideas@python.org> To unsubscribe send an email to python-ideas-le...@python.org <mailto:python-ideas-le...@python.org> https://mail.python.org/mailman3/lists/python-ideas.python.org/ <https://mail.python.org/mailman3/lists/python-ideas.python.org/> Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/6L4W5OB23FBWZ7EZYDNCYSGT2CUAKYSX/ <https://mail.python.org/archives/list/python-ideas@python.org/message/6L4W5OB23FBWZ7EZYDNCYSGT2CUAKYSX/> Code of Conduct: http://python.org/psf/codeofconduct/ <http://python.org/psf/codeofconduct/>


_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/VPSE34Z35XOXGFJMGTMLWDAMF7JKJYOJ/
Code of Conduct: http://python.org/psf/codeofconduct/

--
Eric V. Smith

<<attachment: eric.vcf>>

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/EGSUJ3HDCI6M75AUZ74BFMJEOMYLVFF7/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to