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

@unique errors #1

Closed
ysangkok opened this issue May 7, 2023 · 9 comments
Closed

@unique errors #1

ysangkok opened this issue May 7, 2023 · 9 comments

Comments

@ysangkok
Copy link

ysangkok commented May 7, 2023

on commit bf4507b

trying the command in the readme is erroring

% python --version   
Python 3.11.3
% python plox/plox.py
Traceback (most recent call last):
  File "/home/janus/flipstone/craftinginterpreters-plox/plox/plox.py", line 3, in <module>
    from scanner import Scanner, Token, TokenType
  File "/home/janus/flipstone/craftinginterpreters-plox/plox/scanner.py", line 12, in <module>
    @unique
     ^^^^^^
  File "/home/janus/.pyenv/versions/3.11.3/lib/python3.11/enum.py", line 1561, in unique
    raise ValueError('duplicate values found in %r: %s' %
ValueError: duplicate values found in <enum 'TokenType'>: NUMBER -> STRING, EOF -> STRING

Changing Enum to StrEnum seems to work.

@naringas
Copy link
Owner

naringas commented May 7, 2023

strange, i don't get this error (clearly)... but i'm using python 3.10

I don't understand why this error, the TokenType enum has the @unique decorator. AND the token types that it complains about having dupe values are both values set by auto https://docs.python.org/3/library/enum.html#enum.auto

but we know this parts of the python Enum got intervened between 3.10 and 3.11.

Changed in version 3.11.1: In prior versions, auto() had to be the only thing on the assignment line to work properly.

something warrants a deeper dive... without having yet figured this out, I blame python, it's their bug my code is perfect 😂😅

@naringas
Copy link
Owner

naringas commented May 7, 2023

In python 3.10 there is no such a thing as StrEnum... so why should adding a new kind of Enum, break older python Enums that used to work fine? https://docs.python.org/3/library/enum.html#enum.StrEnum

@ysangkok
Copy link
Author

ysangkok commented May 7, 2023

Yeah, it's weird that the 3.11 changelog doesn't mention changes to auto...

@naringas
Copy link
Owner

naringas commented May 7, 2023

it's a python bug, a regression of some kind. They have been tweaking enum.py

python/cpython#91456
python/cpython#91457

@ysangkok
Copy link
Author

ysangkok commented May 7, 2023

How can it be an existing bug in 3.11.3 if both of those are marked fixed/merged in 2022 and 3.11.3 was released last month?

@naringas
Copy link
Owner

naringas commented May 7, 2023

it's an exisiting bug cuz we just found it, but it's not a known bug, so far as I've looked.

@ysangkok
Copy link
Author

ysangkok commented May 7, 2023

Ah, ok, I understand. Looking at the 91456, that is about aliases, which you don't have. And 91457 was backported as 94156 (note how that is not 91456) which suggests that it should only emit a DeprecationWarning but still work, which it doesn't.

@naringas
Copy link
Owner

naringas commented May 7, 2023

so I suppose that your solution, of using StrEnum instead of Enum is THE workaround... but Python should not break like this between 3.10 and 3.11....

all that remains if filling the bug report to Python. python/cpython#104271

@naringas naringas closed this as completed May 7, 2023
naringas pushed a commit that referenced this issue May 7, 2023
autoappend ";" if not there in the prompt.
implement `_generate_next_value_` for unique Enum with mixed int and str values.

clip the number of reprinted tokens.
@naringas
Copy link
Owner

naringas commented May 9, 2023

I made a fix for this, but I haven't bothered to update my local python version, could you test it?

this is the fix e1d7426#diff-69834159763133611b2ce61f9c7fdd35941c705fc1520ce40f294c9b208852a6L12

@naringas naringas reopened this May 9, 2023
@naringas naringas closed this as completed Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants