Message250355
I found a pretty obscure bug/documentation issue.
It only happens if you use global variables in static methods under doctest.
The thing is that this code fails under doctest, while anyone would expect it to work at first sight:
class foo:
@staticmethod
def bar():
"""
>>> GLOBAL = 5; foo.bar()
5
"""
print(GLOBAL)
The cause of the problem is that the static method has a __globals__ that for reasons beyond my understanding is not equal to the globals when run under doctest.
This might be a doctest bug, or there might be a reason for it that I don't get: than it must be documented, before it stupifies others.
The behaviour is the same under python 2 and 3.
The attached file shows all (written for Python 3, but can be trivially adapted for python 2), including the workaround. |
|
Date |
User |
Action |
Args |
2015-09-10 08:10:44 | jneb | set | recipients:
+ jneb |
2015-09-10 08:10:44 | jneb | set | messageid: <1441872644.04.0.758819356949.issue25049@psf.upfronthosting.co.za> |
2015-09-10 08:10:43 | jneb | link | issue25049 messages |
2015-09-10 08:10:43 | jneb | create | |
|