GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — enum.global_enum: `cls_name` undefined in `global_str` · Issue #93100 · python/cpython

enum.global_enum: cls_name undefined in global_str #93100

New issue
Copy link
New issue
Copy link
Closed
Closed
enum.global_enum: cls_name undefined in global_str#93100
Copy link
Assignees
ethanfurman
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@The-Compiler
The-Compiler
opened on May 23, 2022
Issue body actions

Bug report

In acf7403 (#30582), @ethanfurman implemented a global_enum decorator, replacing the __str__ of an enum with enum.global_str:

cpython/Lib/enum.py

Lines 1638 to 1645 in 760ec89

def global_str(self):
"""
use enum_name instead of class.enum_name
"""
if self._name_ is None:
return "%s(%r)" % (cls_name, self._value_)
else:
return self._name_

(This was later reverted in 42a64c0 and reintroduced in 83d544b, but I believe the code to be the same).

If the ._name_ attribute is None, this uses cls_name, but that's not defined anywhere in that function!

Here is a (somewhat contrived) example:

import enum

@enum.global_enum
class EnumTest(enum.Enum):
    VAL = 1

EnumTest.VAL._name_ = None

print(str(VAL))

this fails with:

Traceback (most recent call last):
  File "/home/florian/tmp/x.py", line 9, in <module>
    print(str(VAL))
          ^^^^^^^^
  File "/usr/lib/python3.11/enum.py", line 1646, in global_str
    return "%s(%r)" % (cls_name, self._value_)
                       ^^^^^^^^
NameError: name 'cls_name' is not defined

(Found by running flake8 over Lib/ out of curiosity, see #93010 (comment))

Your environment

  • CPython versions tested on: Python 3.11.0b1
  • Operating system and architecture: Archlinux x86_64
Reacted by Marcel Guinhos

Activity

  1. The-Compiler
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on May 23, 2022
  2. AlexWaygood
    assigned
    ethanfurman
    on May 23, 2022
  3. AlexWaygood
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    3.11only security fixesonly security fixes
    3.12only security fixesonly security fixes
    on May 23, 2022
  4. ethanfurman
    added a commit that references this issue on May 23, 2022

    [3.11] gh-93100: [Enum] fix missing variable in global_str (GH-93107) (…

    96218f7
  5. ethanfurman commented on May 23, 2022

    @ethanfurman
    ethanfurman
    on May 23, 2022
    Member
    More actions

    Fixed.

  6. ethanfurman
    closed this as completedon May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @ethanfurman
    ethanfurman

Labels

3.11only security fixesonly security fixes3.12only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.