Skip to content

Should avoid changing _value in Enum._missing_ #67

Closed

Description

@AutumnSun1996

Code

from UnityPy.enums import ClassIDType

# two unkonw values
t1 = ClassIDType(-10)
t2 = ClassIDType(-20)

assert t1 == -10, (t1, t1.value)

Error

AssertionError: (<ClassIDType.UnknownType: -1>, -20)

New unkonw value will change the value of previous values.

Bug
The bug is caused by Enum._missing_

@classmethod
def _missing_(cls, value):
ret = ClassIDType.UnknownType
ret._value = value
return ret

ClassIDType.UnknownType is singlenton, so changes to _value should be avoided.

BuildTarget will suffer the same issue.

Didn't find a easy method to fix this. Maybe a custom Enum implemention is reqeuired.

Activity

  1. changed the title [-]Should avoid changing `_value` in Enum._missing_[/-] [+]Should avoid changing `_value` in `Enum._missing_`[/+] on Aug 8, 2021
  2. added 2 commits that reference this issue on Sep 30, 2021
    eb70dfd
    d80ca9e
  3. added a commit that references this issue on Sep 14, 2025
    612cce4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions