Here's an idea I was toying with in thinking about the problem this evening.

Currently, python complains if you try to add a class member that will
conflict with a slot:

>>> class C:
...  __slots__="x"
...  x=1
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: 'x' in __slots__ conflicts with class variable

What if the slots machinery were changed so that there was a warning
propagated instead, and the conflicting member value(s) were saved in some
appropriate place in the class namespace? Maybe something like
__slot_conflicts__, or something like that.

>>> class C:
...  __slots__="x"
...  x=1
...
>>> C.__slot_conflicts__["x"]
1

This would give the decorator the opportunity to find the stuff that was
put in those fields, and sort out the class definition in an expected way.

---
Ricky.

"I've never met a Kentucky man who wasn't either thinking about going home
or actually going home." - Happy Chandler


On Fri, Sep 27, 2019 at 9:39 PM Andrew Barnert via Python-ideas <
python-ideas@python.org> wrote:

> On Sep 27, 2019, at 17:20, Guido van Rossum <gu...@python.org> wrote:
> >
> > Thinking aloud, perhaps this could be done by setting __slots__ to a
> magical value, e.g.
> >
> > class Point:
> >     __slots__ = "__auto__"
> >     x: float
> >     y: float
>
> Would this confuse any existing automated tools (or dataclass-like
> libraries) into thinking you’re declaring slots named _, a, u, t, and o?
>
> (I don’t think there’s any danger of confusing human readers, at least.)
>
> _______________________________________________
> 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/TPCZH4BZYPWCHMYTHZXDQSBHAZ5LSG62/
> Code of Conduct: 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/IPSZOGPXRGEUQHZRYLQTLESB6LL4PVXG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to