[Python-checkins] r45822 - python/trunk/Lib/inspect.py

Neal Norwitz nnorwitz at gmail.com
Fri May 5 06:18:49 CEST 2006


Can we get a test case for this? Docs should probably be updated with
the limitation too. -- n

On 4/30/06, phillip.eby <python-checkins at python.org> wrote:
> Author: phillip.eby
> Date: Sun Apr 30 17:59:26 2006
> New Revision: 45822
>
> Modified:
>    python/trunk/Lib/inspect.py
> Log:
> Fix infinite regress when inspecting <string> or <stdin> frames.
>
>
> Modified: python/trunk/Lib/inspect.py
> ==============================================================================
> --- python/trunk/Lib/inspect.py (original)
> +++ python/trunk/Lib/inspect.py Sun Apr 30 17:59:26 2006
> @@ -353,7 +353,13 @@
>          if 'b' in mode and string.lower(filename[-len(suffix):]) == suffix:
>              # Looks like a binary file.  We want to only return a text file.
>              return None
> -    if os.path.exists(filename) or hasattr(getmodule(object), '__loader__'):
> +    if os.path.exists(filename):
> +        return filename
> +    # Ugly but necessary - '<stdin>' and '<string>' mean that getmodule()
> +    # would infinitely recurse, because they're not real files nor loadable
> +    # Note that this means that writing a PEP 302 loader that uses '<'
> +    # at the start of a filename is now not a good idea.  :(
> +    if filename[:1]!='<' and hasattr(getmodule(object), '__loader__'):
>          return filename
>
>  def getabsfile(object):
> _______________________________________________
> Python-checkins mailing list
> Python-checkins at python.org
> http://mail.python.org/mailman/listinfo/python-checkins
>


More information about the Python-checkins mailing list