[Python-ideas] Re: def variable = value
Serhiy Storchaka writes: > They have. Both function and type classes have constructors Ah, right. "First-class values", of course they do. Thanks! Steve ___ 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/D7ESLIWVWZ6DJ6PUL7MHHSYFL7UASLOQ/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: def variable = value
Hi Serhiy Thank you for so clearly explaining how names get passed to function and class constructors. You also wrote: > We do not have generalized way to call arbitrary constructor with > automatically passing __name__, __qualname__ and __module__. And it would > be convenient. > > create namedtuple Point(x, y, z=0) > [further examples snipped] We can already do something similar by writing (not tested) class Point(Hack): namedtuple = lambda x, y, z=0: None provided Hack has a suitable value. I don't see a way to do much better than this, without introducing a new language keyword. For example allow signature(x, y, z=0) to be an EXPRESSION that returns a function signature. By the way, class Point(Hack): def namedtuple(x, y, z=0): pass gives a syntax error at 'def'. -- Jonathan ___ 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/CRSD2XZXJTRD4VNPRAUAFPKBELMA2FG3/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: def variable = value
24.10.21 15:20, Stephen J. Turnbull пише: > What do you mean by "constructor" here? Normally that word refers to > methods that populate the attributes of instances (in Python, __init__ > and__new__). But functions and methods don't have such, so you must > mean something else? They have. Both function and type classes have constructors and they are called when a function or class is created. Values of __name__, __qualname__ and __module__ attributes are directly or indirectly passed to constructors. We do not have generalized way to call arbitrary constructor with automatically passing __name__, __qualname__ and __module__. And it would be convenient. create namedtuple Point(x, y, z=0) create enum Mode(read, write, append) create NewType UserId(int) create TypeVar T ___ 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/VIRQ44BQKO2ENNL42PCNCVHVLPZMTXYV/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: def variable = value
Jonathan Fine writes: > >From my phone. > > An important thing about def x and class A is that the strings x and A are > made available to the constructor for x and A respectively. What do you mean by "constructor" here? Normally that word refers to methods that populate the attributes of instances (in Python, __init__ and__new__). But functions and methods don't have such, so you must mean something else? > The same is not true for x=val. And cannot be, since no construction is involved, just evaluation of the rhs expression, and binding of the name to the result. > > Jonathan > ___ > 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/GMUQMIGOHZGXF5VA6DG5SBM7WQRQBF7O/ > 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/2FSNZ3FRSFDLWZS24RMLROHN2HGY5LWZ/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: def variable = value
>From my phone. An important thing about def x and class A is that the strings x and A are made available to the constructor for x and A respectively. The same is not true for x=val. Jonathan ___ 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/GMUQMIGOHZGXF5VA6DG5SBM7WQRQBF7O/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: def variable = value
Why would anyone want to type: def variable = value when they could just type: variable = value instead? Perhaps if I was being paid by the character typed... def my__really__good__variable = ( value )# Assign value to my__really__good__variable. *wink* But all joking aside, what benefit would this "def" statement have? Why would I want to use it? On Sat, Oct 23, 2021 at 04:37:20PM -, blek blek wrote: > I was thinking of a "def" statement in Python. > Its really weird that it can define only method, since it means "define". It means *define function*, not just "define anything". We don't use def to define classes, or modules, or lists, or other objects. -- Steve ___ 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/D6ALT2A35PJFD64ZBZTMOLRBVDW27AF6/ Code of Conduct: http://python.org/psf/codeofconduct/