Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnboundLocalError in cgitb.py #39713

Closed
jemfinch mannequin opened this issue Dec 16, 2003 · 8 comments
Closed

UnboundLocalError in cgitb.py #39713

jemfinch mannequin opened this issue Dec 16, 2003 · 8 comments
Assignees
Labels
stdlib Python modules in the Lib dir

Comments

@jemfinch
Copy link
Mannequin

jemfinch mannequin commented Dec 16, 2003

BPO 861340
Nosy @smontanaro
Files
  • lookup.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/smontanaro'
    closed_at = <Date 2005-05-20.03:26:45.000>
    created_at = <Date 2003-12-16.23:09:19.000>
    labels = ['library']
    title = 'UnboundLocalError in cgitb.py'
    updated_at = <Date 2005-05-20.03:26:45.000>
    user = 'https://bugs.python.org/jemfinch'

    bugs.python.org fields:

    activity = <Date 2005-05-20.03:26:45.000>
    actor = 'skip.montanaro'
    assignee = 'skip.montanaro'
    closed = True
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2003-12-16.23:09:19.000>
    creator = 'jemfinch'
    dependencies = []
    files = ['1142']
    hgrepos = []
    issue_num = 861340
    keywords = []
    message_count = 8.0
    messages = ['19427', '19428', '19429', '19430', '19431', '19432', '19433', '19434']
    nosy_count = 3.0
    nosy_names = ['skip.montanaro', 'nnorwitz', 'jemfinch']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue861340'
    versions = ['Python 2.3']

    @jemfinch
    Copy link
    Mannequin Author

    jemfinch mannequin commented Dec 16, 2003

    Here's the exception:

    Exception
    return cgitb.text((E, e, tb)).rstrip('\r\n')
    File "/usr/lib/python2.3/cgitb.py", line 197, in text
    vars = scanvars(reader, frame, locals)
    File "/usr/lib/python2.3/cgitb.py", line 76, in scanvars
    parent = value
    UnboundLocalError: local variable 'value' referenced
    before assignment

    And here's the code:

            if lasttoken == '.': 
                if parent is not \_\_UNDEF__: 
                    value = getattr(parent, token, \_\_UNDEF__) 
                    vars.append((prefix + token, prefix, value)) 
            else: 
                where, value = lookup(token, frame, locals) 
                vars.append((token, where, value)) 
        elif token == '.': 
            prefix += lasttoken + '.' 
            parent = value 
    

    If lasttoken is '.' and parent is __UNDEF__, value doesn't
    get set. I'd offer a patch, but I really have no idea what this
    code is doing and so don't know what to set value to.

    @jemfinch jemfinch mannequin closed this as completed Dec 16, 2003
    @jemfinch jemfinch mannequin assigned smontanaro Dec 16, 2003
    @jemfinch jemfinch mannequin added the stdlib Python modules in the Lib dir label Dec 16, 2003
    @jemfinch jemfinch mannequin closed this as completed Dec 16, 2003
    @jemfinch jemfinch mannequin assigned smontanaro Dec 16, 2003
    @jemfinch jemfinch mannequin added the stdlib Python modules in the Lib dir label Dec 16, 2003
    @nnorwitz
    Copy link
    Mannequin

    nnorwitz mannequin commented Dec 18, 2003

    Logged In: YES
    user_id=33168

    Jeremy, can you attach a complete test case?

    Skip, I realize you didn't write the scanvars code (Ping
    did), but you did add text. So maybe you have an idea.
    From a brief scan, it looks like if value is initialized to
    None, the code might work.

    @smontanaro
    Copy link
    Contributor

    Logged In: YES
    user_id=44345

    Sorry, I have no idea what it does either. I'll look into it a bit,
    but don't expect a miracle. :-(

    @smontanaro
    Copy link
    Contributor

    Logged In: YES
    user_id=44345

    I pulled scanvars() and lookup() out into a separate file and
    instrumented things a little. From staring at the code I thought
    that perhaps it didn't handle the case where the line starts with
    a dot separating an object and its attribute. I can't provoke a
    failure in that situation though. See attached lookup.py.

    Jeremy, can you fiddle it to make it fail?

    @jemfinch
    Copy link
    Mannequin Author

    jemfinch mannequin commented Dec 18, 2003

    Logged In: YES
    user_id=99508

    To be honest, it's just something I ran into in my own test suite
    when my exception-handling logging code caught an exception I
    didn't expect to get raised. Since I have no idea what the code in
    cgitb that's raising the exception is actually doing, I really don't
    know how to begin to try and narrow it down to a test case.

    @jemfinch
    Copy link
    Mannequin Author

    jemfinch mannequin commented Dec 18, 2003

    Logged In: YES
    user_id=99508

    The code that caused the raised exception (which subsequently
    triggered the exception in cgitb) was this:

        outputstr = '%d %s match \\'%s\\' (%s):' % (len(bugs), \\ 
        utils.pluralize(len(bugs), 'bug'), 
        searchstr, utils.commaAndify(keywords, And='AND')) 
    

    That's actually from the diff where I changed it to be a bit more
    idiomatic :) It wasn't my code, I promise!

    @nnorwitz
    Copy link
    Mannequin

    nnorwitz mannequin commented Dec 18, 2003

    Logged In: YES
    user_id=33168

    Jeremy, that's still not enough to reproduce the bug. What
    exception was thrown by the code below and from where? What
    were the values of bugs, searchstr, and keywords? What are
    the definitions for utils.pluralize() and utils.commaAndify()?

    @smontanaro
    Copy link
    Contributor

    Logged In: YES
    user_id=44345

    Looks like this was fixed at some point. The local variable value is
    clearly initialized in scanvars() at this point.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant