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

pydoc.Helper leaks several for loop variables #90705

Closed
sobolevn opened this issue Jan 27, 2022 · 1 comment
Closed

pydoc.Helper leaks several for loop variables #90705

sobolevn opened this issue Jan 27, 2022 · 1 comment
Labels
3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

BPO 46547
Nosy @sobolevn
PRs
  • bpo-46547: remove leaking vars into pydoc.Helper namespace #30957
  • 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 = None
    closed_at = None
    created_at = <Date 2022-01-27.11:40:53.011>
    labels = ['type-bug', 'library', '3.11']
    title = '`pydoc.Helper` leaks several `for` loop variables'
    updated_at = <Date 2022-01-27.11:43:23.166>
    user = 'https://github.com/sobolevn'

    bugs.python.org fields:

    activity = <Date 2022-01-27.11:43:23.166>
    actor = 'sobolevn'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2022-01-27.11:40:53.011>
    creator = 'sobolevn'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46547
    keywords = ['patch']
    message_count = 1.0
    messages = ['411856']
    nosy_count = 1.0
    nosy_names = ['sobolevn']
    pr_nums = ['30957']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue46547'
    versions = ['Python 3.11']

    @sobolevn
    Copy link
    Member Author

    Here's the problem. pydoc.Helper is defined as:

    class Helper:
        for topic, symbols_ in _symbols_inverse.items():
            for symbol in symbols_:
                topics = symbols.get(symbol, topic)
                if topic not in topics:
                    topics = topics + ' ' + topic
                symbols[symbol] = topics
    

    Link:

    cpython/Lib/pydoc.py

    Lines 1877 to 1882 in 08c0ed2

    for topic, symbols_ in _symbols_inverse.items():
    for symbol in symbols_:
    topics = symbols.get(symbol, topic)
    if topic not in topics:
    topics = topics + ' ' + topic
    symbols[symbol] = topics

    It causes some unwanted consequences: topic, symbols_, symbol are leaking to the class's namespace. Example:

    >>> import pydoc
    >>> pydoc.Helper.symbol
    'J'
    >>> pydoc.Helper.topic
    'COMPLEX'
    >>> pydoc.Helper.symbols_
    ('j', 'J')
    

    There's also topics var, but it is shadowed later.

    So, I propose deleting all intermediate variables right after the for loop.

    @sobolevn sobolevn added 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jan 27, 2022
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant