This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jneb
Recipients jneb
Date 2015-09-10.08:10:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1441872644.04.0.758819356949.issue25049@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2015-09-10 08:10:44jnebsetrecipients: + jneb
2015-09-10 08:10:44jnebsetmessageid: <1441872644.04.0.758819356949.issue25049@psf.upfronthosting.co.za>
2015-09-10 08:10:43jneblinkissue25049 messages
2015-09-10 08:10:43jnebcreate