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

Zero-valued flag enum has no name #118820

Closed
apple1417 opened this issue May 9, 2024 · 5 comments
Closed

Zero-valued flag enum has no name #118820

apple1417 opened this issue May 9, 2024 · 5 comments
Labels
docs Documentation in the Doc dir stdlib Python modules in the Lib dir

Comments

@apple1417
Copy link

apple1417 commented May 9, 2024

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

@apple1417 apple1417 added the docs Documentation in the Doc dir label May 9, 2024
@Eclips4 Eclips4 added the stdlib Python modules in the Lib dir label May 9, 2024
@nineteendo
Copy link
Contributor

nineteendo commented May 9, 2024

The code for reference:

if member_value or aliases:

cpython/Lib/enum.py

Lines 1527 to 1528 in 82acc5f

else:
pseudo_member._name_ = None

Added in the same commit.

@nineteendo
Copy link
Contributor

cc @ethanfurman.

@ethanfurman
Copy link
Member

The zero-flag name is constructed from its members -- it just doesn't have any members. This could certainly be mentioned in the docs.

@nineteendo
Copy link
Contributor

I'll make a pull request with an example.

@nineteendo
Copy link
Contributor

It has been a month, does someone still need to review my pull request?

ethanfurman pushed a commit that referenced this issue Jun 19, 2024
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 19, 2024
(cherry picked from commit ed5ae6c)

Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 19, 2024
(cherry picked from commit ed5ae6c)

Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
ethanfurman pushed a commit that referenced this issue Jun 19, 2024
…20759)

gh-118820: Zero-valued flag enum has no name (GH-118848)
(cherry picked from commit ed5ae6c)

Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
ethanfurman pushed a commit that referenced this issue Jun 19, 2024
…0758)

gh-118820: Zero-valued flag enum has no name (GH-118848)
(cherry picked from commit ed5ae6c)

Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
mrahtz pushed a commit to mrahtz/cpython that referenced this issue Jun 30, 2024
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
noahbkim pushed a commit to hudson-trading/cpython that referenced this issue Jul 11, 2024
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
estyxx pushed a commit to estyxx/cpython that referenced this issue Jul 17, 2024
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir stdlib Python modules in the Lib dir
Projects
None yet
Development

No branches or pull requests

4 participants