Steven D'Aprano <[email protected]> added the comment:
Anthony, can you please explain what you mean when you describe generators as
"mutable"? I don't understand what you mean.
To *me*, the value of a generator, in so far as comparisons goes, is its
identity, not its invisible internal state. You can test that by noting that
two generators with the same state compare unequal:
py> def gen():
... yield 1
...
py> a = gen()
py> b = gen()
py> a == b
False
Furthermore, the hash of the generator doesn't change when its internal state
changes.
py> hash(a)
192456114
py> next(a)
1
py> hash(a)
192456114
And as for functions being "immutable", you can attach arbitrary attributes to
them, so their object state can change. Does that make them mutable? Either
way, it doesn't matter, since functions are also compared by identity. Their
value is their identity, not their state. (Two functions with the same internal
state are compared as unequal.)
----------
nosy: +steven.daprano
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue38769>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com