On 6/15/2018 8:42 PM, Greg Ewing wrote:
Mikhail V wrote:
It s just very uncommon to see standalone statements like:
x.method()

for me it came into habit to think that it lacks the left-hand part and =.

You must be looking at a very limited and non-typical
corpus of Python code. Mutating method calls are
extremely common in most Python code I've seen.

You seem to be trying to reason about Python as though
it were intended to be used in a functional style, but
it's not. Making guesses about it based on how something
would be done in a functinal language will get you
nowhere.

 > I am not sure about x.method() form - was it meant to hint to the user
about anything? It seemed to me so when I started to learn Python, but its not.

The fact that something is a method does not, and was never
intended to, imply anytbing about whether it is mutating.

However, there *is* a fairly easy way to tell, most of
the time, when you're *reading* code. There's a convention
that mutating methods don't return anything other than
None, so mutating method calls reveal themselves by the
fact that the result is not used.

Conversely, a method call whose result *is* used is most
likely non-mutating. (It's possible that it could both
return a value and have a side effect, but that's frowned
upon,

Except for set/list.pop and dict.popitem.

 and you'll pretty much never see it in any builtin
or stdlib API.)

As for writing code, you just have to rely on memory and
documentation, just like you do with most aspects of any
language and its libraries.

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/



--
Terry Jan Reedy

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to