Search code examples
pythontypesenumsassert

AssertionError: assert <enum 'AccessId'> is str + where <enum 'AccessId'> = type(<AccessId.BUYLIST_TAB: 'Listes'>)


this is strange : my class is recognized as an Enum even tho i didn't inherite from it

class AccessId:
    MENU_TAB: str = "Menu"
    BASKET_TAB: str = "Panier"
    BUYLIST_TAB: str = "Listes"
    HOME_TAB: str = "Accueil"
    DISCOUNT_TAB: str = "Promos"
    DELETE_PRODUCT: str = "Supprimer l'article"

I tried to debug with this assertion :

assert type(AccessId.HOME_TAB) is str

And got :

AssertionError: assert <enum 'AccessId'> is str
 +  where <enum 'AccessId'> = type(<AccessId.HOME_TAB: 'Accueil'>)

I do not understand, please, someone, help me

Things i tried :

  • Cleared __pycache__ folders
  • Tried with assert type(AccessId.HOME_TAB.value) is str since it's apparently an enum and it didn't find the attribute value.
  • Tried in console type(AccessId.HOME_TAB) is str and got True wtf
  • Created a similar class and got no AssertionError (???)

Solution

  • I found why, please check if your IDE doesn't auto-import from the wrong directory. In my case, it was the build directory where i previously subclass Enum with AccessId.