[issue19472] inspect.getsource() raises a wrong exception type
New submission from Marco Buttu: I was looking at inspect.getsource(). In Python 3.3 and 3.4 either the docstring and the online doc say it raises a OSError, and in fact:
import inspect def foo(): ... pass ... inspect.getsource(foo) Traceback (most recent call last): ... OSError: could not get source code
However, getsource() calls getfile(), and this one raises a TypeError:
inspect.getsource(0) Traceback (most recent call last): ... TypeError: 0 is not a module, class, method, function, traceback, frame, or code object
---------- assignee: docs@python components: Documentation, Library (Lib) messages: 201891 nosy: docs@python, marco.buttu priority: normal severity: normal status: open title: inspect.getsource() raises a wrong exception type type: behavior versions: Python 3.3, Python 3.4 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue19472> _______________________________________
Mark Lawrence added the comment: @Yury do you agree with this? ---------- nosy: +BreamoreBoy, yselivanov _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue19472> _______________________________________
Yury Selivanov added the comment:
@Yury do you agree with this?
I think it's a perfectly normal behaviour. OSError is raised for valid kind of objects, and TypeError is raised when you're passing something weird. That's a pretty common practice is Python. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue19472> _______________________________________
Changes by Yury Selivanov <yselivanov@gmail.com>: ---------- resolution: -> not a bug status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue19472> _______________________________________
participants (3)
-
Marco Buttu
-
Mark Lawrence
-
Yury Selivanov