Skip to content

[Enum] minor fixes and cleanup #110905

@eendebakpt

Description

@eendebakpt

Bug report

Bug description:

The _is_private method has incorrect results on attributes starting with a triple underscore. Example:

import enum
enum._is_private('X', '_X___test') # returns True

The relevant code is:

def _is_private(cls_name, name):
    pattern = '_%s__' % (cls_name, )
    pat_len = len(pattern)
    if (
            len(name) > pat_len
            and name.startswith(pattern)
            and name[pat_len:pat_len+1] != ['_']
            and (name[-1] != '_' or name[-2] != '_')
        ):
        return True
    else:
        return False

The check name[pat_len:pat_len+1] != ['_'] is always False, since name[pat_len:pat_len+1] is a str and ['_'] a list.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions