I noticed the following behavior in Python:
>>> class foo:
... def __init__(self, x=0):
... self.x = x
... def bar(self):
... self.x = self.x + 1
...
>>> def f(a=foo()):
... a.bar()
... return a
...
>>> c = f()
>>> c.x
1
>>> d = f()
>>> d.x
2
>>> d == c
True
It is as if the variable a
became global, which is not true but still calling the method f
the variable a
does not re-instantiate as I expected.
What is the reason behind this?