New submission from Jurjen N.E. Bos:

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.

----------
components: Library (Lib)
files: t.py
messages: 250355
nosy: jneb
priority: normal
severity: normal
status: open
title: Strange behavior under doctest: staticmethods have different __globals__
type: enhancement
Added file: http://bugs.python.org/file40422/t.py

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

Reply via email to