On Wed, Jan 19, 2022 at 6:21 AM Joao S. O. Bueno <jsbu...@python.org.br> wrote:
> Here is another hint that this usage would not resolve the problem of >> > having a literal frozenset. Even in the core of this discussion, with folks > participating and knowing what they are talking about, the first thing that > comes to mind when seeing a method call is that the target set would > be copied. > sure, and in the general case, a_set.frozen() would presumably return a copy. as does frozenset(a_set) -- which is all we have at the moment. > But upon seeing a method call, we can just think first of a runtime > behavior > Correctly, btw. Any optimization there would be an exception, that people > would > have to know by heart. > But people shouldn't have to think about to trigger a compiler optimization anyway, that's just a nice bonus the compiler does for you. If this does all come to pass, then: s = {3,8,2}.frozen() will be slightly faster, in some case, than s = frozenset({3,8,2} but the result would be the same. There are plenty of tricks to in python to get a touch more performance, this would just be one more and frankly pretty rare that it would make an noticable difference at all. +1 on this +0 on f{} -1 on making frozenset a keyword -CHB On Wed, Jan 19, 2022 at 10:31 AM Steven D'Aprano <st...@pearwood.info> > wrote: > >> On Wed, Jan 19, 2022 at 07:12:04AM -0500, Ricky Teachey wrote: >> > Why does it need to be called at all? >> > >> > {1, 2, 3}.frozen >> >> For the same reason that most methods are methods, not properties. >> >> The aim of a good API is not to minimize the amount of typing, it is to >> communicate the *meaning* of the code as best as possible. >> >> `{1, 2, 3}.frozen` says that the result is an attribute (property, >> member) of the set. Like *name* to a person, or *tail* to a dog, the >> attribute API represents something which is part of, or a quality of, >> the object. The frozenset is not an attribute of the set, it is a >> transformation of the set into a different type. >> >> A transformation should be written as an explicit function or method >> call, not as attribute access. Yes, we can hide that transformation >> behind a property just to save typing two characters, but that is an >> abuse of notation. >> >> Also, it is standard in Python to avoid properties if the computation >> could be expensive. Copying a large set or millions of elements into a >> frozenset could be expensive, so we should keep it a method call. >> >> >> -- >> 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/WS5IXNJKETM5JICWCYJPDOF2HNK75DNK/ >> 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/T55L2JOA6PVHV473RHYU45SQOHHH3IHQ/ > Code of Conduct: http://python.org/psf/codeofconduct/ > -- Christopher Barker, PhD (Chris) Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython
_______________________________________________ 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/QIR6AGB3PU7AJVI3366MVHN36KCXKUQS/ Code of Conduct: http://python.org/psf/codeofconduct/