Skip to content

Handle empty lists in strict email.utils.parseaddr #159350

Description

@esadomer

The strict path in email.utils.parseaddr() handles list input by reading its first item without checking for an empty list. The non-strict path returns an empty address pair for the same input.

Reproducer, run with the interpreter built from the CPython checkout:

from email.utils import parseaddr

print(parseaddr([], strict=False))
print(parseaddr([]))

Expected: Both calls return ('', '').

Observed: The default strict call raises IndexError.

Environment: CPython main, Windows debug build.

Linked PRs

Activity

  1. added
    type-featureA feature request or enhancement
    stdlibStandard Library Python modules in the Lib/ directory
    and removed
    stdlibStandard Library Python modules in the Lib/ directory
    on Oct 14, 2026
  2. merwok commented on Oct 20, 2026

    @merwok
    Member

    Is this incorrect given the documentation of this function?
    What is strict mode used for?

    Should the function really handle this, or should the calling site check its data and not call the function on empty lists?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-emailtype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions