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 = field(kw_only=True, default='foo')
      d: Any = field(kw_only=True)
      e: Any = field(kw_only=True, default=0.0)
      f: Any = field(kw_only=True)
      g: Any = field(kw_only=True, default=())
      h: Any = field(kw_only=True, default='bar')
      i: Any = field(kw_only=True, default=3+4j)
      j: Any = field(kw_only=True, default=10)
      k: Any = field(kw_only=True)

That's way too verbose for me.
Why not:

@dataclasses.dataclass(kw_only=True)
class LotsOfFields:
      a: Any = field(kw_only=False)
      b: Any = 0
      c: Any = 'foo'
      d: Any
      e: Any = 0.0
      f: Any
      g: Any = ()
      h: Any = 'bar'
      i: Any = 3+4j
      j: Any = 10
      k: Any

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.

Eric
Avoids weirdness with pragma and singletons that make the order of
parameters important.
_______________________________________________
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/W7VT6KBZETMVBBCU722VTZWP6777SFX4/
Code of Conduct: http://python.org/psf/codeofconduct/

--
Eric V. Smith

_______________________________________________
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/PMSBCGLZSGFNRGV6LQFEWVJXT5D6XBSQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to