Content-Length: 292701 | pFad | http://github.com/python/cpython/issues/136738

6C Redundant Comparison and Unused parts of code · Issue #136738 · python/cpython · GitHub
Skip to content

Redundant Comparison and Unused parts of code #136738

@LM4O322

Description

@LM4O322

Feature or enhancement

Proposal:

while value and value[0] != ';':
        try:
            token, value = get_mailbox(value)
            mailbox_list.append(token)
        except errors.HeaderParseError:
            leader = None

Each iteration of the loop is accompanied by assigning the value None to the leader variable, so

else:
                token, value = get_invalid_mailbox(value, ',;')
                if leader is not None:
                    token[:0] = [leader]
                mailbox_list.append(token)
                mailbox_list.defects.append(errors.InvalidHeaderDefect(
                    "invalid mailbox in mailbox-list"))

the code will not be executed after checking leader for None. because the value of the leader variable will not change from the moment of the initial assignment until the else block is called.

Link to the method code:

def get_mailbox_list(value):


Same situation was found here:

def get_address_list(value):

Specifically:

while value:
        try:
            token, value = get_address(value)
            address_list.append(token)
        except errors.HeaderParseError:
            leader = None

The leader variable has been set to NULL...

else:
                token, value = get_invalid_mailbox(value, ',')
                if leader is not None:
                    token[:0] = [leader]
                address_list.append(Address([token]))
                address_list.defects.append(errors.InvalidHeaderDefect(
                    "invalid address in address-list"))

...which has not changed at the time the else block was executed. This behavior occurs at each iteration of the loop.

I will try to form a pull request for correction.


Found by Linux Verification Center with SVACE

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThe issue will be closed if no feedback is providedstdlibPython modules in the Lib dirtopic-emailtype-refactorCode refactoring (with no changes in behavior)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: http://github.com/python/cpython/issues/136738

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy