[New-bugs-announce] [issue4845] warnings system and inspect module disagree about

Jean-Paul Calderone report at bugs.python.org
Mon Jan 5 17:00:40 CET 2009


New submission from Jean-Paul Calderone <exarkun at divmod.com>:

Here's a transcript demonstrating the disagreement:

  exarkun at charm:~$ mkdir warningexample
  exarkun at charm:~$ cd warningexample/
  exarkun at charm:~/warningexample$ mkdir foo
  exarkun at charm:~/warningexample$ touch foo/__init__.py
  exarkun at charm:~/warningexample$ cat > foo/bar.py
  import warnings
  def foo():
        warnings.warn("foo")
  exarkun at charm:~/warningexample$ python -c 'import foo.bar'
  exarkun at charm:~/warningexample$ mv foo bar
  exarkun at charm:~/warningexample$ python -c 'import bar.bar; bar.bar.foo()'
  bar/bar.py:3: UserWarning: foo
    warnings.warn("foo")
  exarkun at charm:~/warningexample$ python -c 'import bar.bar, inspect;
print inspect.getabsfile(bar.bar.foo)'
  /home/exarkun/warningexample/foo/bar.py
  exarkun at charm:~/warningexample$ 

Notice that the warning is emitted for the file bar/bar.py but the
inspect module claims that the function which emitted the warning is
defined in /home/exarkun/warningexample/foo/bar.py.  It seems that the
warning system has somehow noticed that the .pyc file has the wrong
source file listed and has figured out the correct file name, whereas
the inspect module is blindly following the contents of the .pyc file.

It would be great if the inspect module were at least as good at
figuring out filenames as the warnings system.

----------
components: Library (Lib)
messages: 79159
nosy: exarkun
severity: normal
status: open
title: warnings system and inspect module disagree about
type: behavior

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4845>
_______________________________________


More information about the New-bugs-announce mailing list