[issue33587] inspect.getsource performs unnecessary filesystem stat call which is ignored in some circumstances

Pankaj Pandey report at bugs.python.org
Sun May 20 12:38:49 EDT 2018


New submission from Pankaj Pandey <pankaj86 at gmail.com>:

The specific os.path.exists() call is shown here: https://github.com/python/cpython/pull/6805

If the filename is already in linecache or the module has a PEP 302 loader, then the os.path.exists() call is ignored. Hence it is better to call it only if its value is needed.

Attached a very simple case which shows the impact of the change:

----------
files: inspect_stack_perf.py
messages: 317186
nosy: Pankaj Pandey
priority: normal
pull_requests: 6667
severity: normal
status: open
title: inspect.getsource performs unnecessary filesystem stat call which is ignored in some circumstances
Added file: https://bugs.python.org/file47607/inspect_stack_perf.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33587>
_______________________________________


More information about the Python-bugs-list mailing list