8000 Zero-valued flag enum has no name · Issue #118820 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
Zero-valued flag enum has no name #118820
Closed
Closed
@apple1417

Description

@apple1417

Documentation

Quoting Doc/howto/enum.rst:1148:

- names of pseudo-flags are constructed from their members' names::

    >>> (Color.RED | Color.GREEN).name
    'RED|GREEN'

This section was originally added in 7aaeb2a3.

If you have a zero-valued flag, and you didn't explicitly give it a name, this doesn't seem to apply, it returns None instead.

class NoZero(Flag):
    ONE = 1

class HasZero(Flag):
    ZERO = 0
    ONE = 1

print(NoZero(0).name, type(NoZero(0).name))   # None <class 'NoneType'>
print(HasZero(0).name, type(HasZero(0).name)) # ZERO <class 'str'>

I'm not entirely sure if this should be considered a documentation issue or a bug report (or both). It doesn't really feel like zero should be treated any differently from other unnamed combinations. But at the same time, I've tested, and this is already the existing behavior in 3.10 through 3.12, and it doesn't seem to be documented anywhere.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dirstdlibPython modules in the Lib dir

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0