Ammar Askar <am...@ammaraskar.com> added the comment:

An easier way to understand might be to just write out the generator expression 
"manually":

  def generator_expression():
    for k, v in sorted(self.__dict__.items()):
      yield k
  return hash(my_generator_expression())

Would you say that `generator_expression` here is mutable or immutable? The 
code that underpins how it generates values is clearly immutable just like 
functions but the values it closes over can be changed.

Another minimal example:

>>> def f():
...   yield from some_list
...
>>> some_list = [1,2,3]
>>> list(f())
[1, 2, 3]
>>> some_list = [1,2,3,4,5]
>>> list(f())
[1, 2, 3, 4, 5]

Would you say that `f` is immutable or mutable in this case?

----------
nosy: +ammar2

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue38769>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to