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

Mypyc IntEnum undeclared name error while compiling #17796

Closed
CoolCat467 opened this issue Sep 20, 2024 · 2 comments
Closed

Mypyc IntEnum undeclared name error while compiling #17796

CoolCat467 opened this issue Sep 20, 2024 · 2 comments
Labels
bug mypy got something wrong topic-mypyc mypyc bugs

Comments

@CoolCat467
Copy link

Bug Report

Class attributes created with IntEnum are not created properly

To Reproduce

minimax.py

from __future__ import annotations

from enum import IntEnum, auto


class Player(IntEnum):
    """Enum for player status."""

    MIN = auto()
    MAX = auto()

print(f'{Player.MAX = }')
mypyc minimax.py

Expected Behavior

No issues compiling

Actual Behavior

running build_ext
building 'minimax' extension
x86_64-linux-gnu-gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O2 -Wall -fPIC -I/home/<my username>/.local/lib/python3.12/site-packages/mypyc/lib-rt -I/usr/include/python3.12 -c build/__native.c -o build/temp.linux-x86_64-cpython-312/build/__native.o -O3 -g1 -Werror -Wno-unused-function -Wno-unused-label -Wno-unreachable-code -Wno-unused-variable -Wno-unused-command-line-argument -Wno-unknown-warning-option -Wno-unused-but-set-variable -Wno-ignored-optimization-argument -Wno-cpp
build/__native.c: In function ‘CPyDef___top_level__’:
build/__native.c:415:17: error: ‘CPyStatic_Player___MAX’ undeclared (first use in this function)
  415 |     cpy_r_r94 = CPyStatic_Player___MAX;
      |                 ^~~~~~~~~~~~~~~~~~~~~~
build/__native.c:415:17: note: each undeclared identifier is reported only once for each function it appears in
At top level:
cc1: note: unrecognized command-line option ‘-Wno-ignored-optimization-argument’ may have been intended to silence earlier diagnostics
cc1: note: unrecognized command-line option ‘-Wno-unknown-warning-option’ may have been intended to silence earlier diagnostics
cc1: note: unrecognized command-line option ‘-Wno-unused-command-line-argument’ may have been intended to silence earlier diagnostics
error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1

Your Environment

  • Mypy version used: mypy 1.11.2 (compiled: yes)
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: Python 3.12.3 (main, Sep 11 2024, 14:17:37) [GCC 13.2.0] on linux
  • GCC version used: gcc (Ubuntu 13.2.0-23ubuntu4) 13.2.0
@CoolCat467 CoolCat467 added the bug mypy got something wrong label Sep 20, 2024
@CoolCat467 CoolCat467 changed the title Mypyc IntEnum undeclared name error Mypyc IntEnum undeclared name error while compiling Sep 20, 2024
@Alir3z4
Copy link

Alir3z4 commented Nov 6, 2024

I have a very similar problem;

from enum import Enum

class PreCommitMode(str, Enum):
    changed = "changed"
    staged = "staged"
    full = "full"

mode = PreCommitMode.changed

if mode in [PreCommitMode.changed, PreCommitMode.staged]:
    print(f"Hey {mode}")

Produces:

build/__native_2650c38b35f4f94cf2d8.c: In function ‘CPyDef_development___pre_commit’:
build/__native_2650c38b35f4f94cf2d8.c:10461:17: error: ‘CPyStatic_development___PreCommitMode___changed’ undeclared (first use in this function); did you mean ‘CPyType_development___PreCommitMode’?
10461 |     cpy_r_r45 = CPyStatic_development___PreCommitMode___changed;
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                 CPyType_development___PreCommitMode
build/__native_2650c38b35f4f94cf2d8.c:10461:17: note: each undeclared identifier is reported only once for each function it appears in
build/__native_2650c38b35f4f94cf2d8.c:10477:17: error: ‘CPyStatic_development___PreCommitMode___staged’ undeclared (first use in this function); did you mean ‘CPyType_development___PreCommitMode’?
10477 |     cpy_r_r48 = CPyStatic_development___PreCommitMode___staged;
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                 CPyType_development___PreCommitMode

@sterliakov sterliakov added the topic-mypyc mypyc bugs label Feb 13, 2025
@sterliakov
Copy link
Collaborator

The first snippet works fine in mypyc == 1.14.0 and newer, the second since 1.15.0 - these seem to be different issues, but both are fixed now. (#18426 and #18178)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-mypyc mypyc bugs
Projects
None yet
Development

No branches or pull requests

3 participants