Skip to content

ninyawee/autoname

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

autoname

an enum AutoName from python docs with multiple stringcase options.

Get Started

$ pip install autoname
from autoname import AutoName
from enum import auto


# an enum class
class GameType(AutoName):
    INDIE = auto()


print(GameType.INDIE.value)  # "INDIE"

# could be alternative in pydantic instead of literal
from pydantic import BaseModel


class Game(BaseModel):
    type: GameType

Also have others stringcases coverter

  1. AutoNameLower - convert name value to lowercase
  2. AutoNameUpper - convert name value to uppercase

e.g.

from autoname import AutoNameLower
from enum import auto

class GameType(AutoNameLower):
    INDIE = auto()

print(GameType.INDIE.value) # "indie"

You could also bring your own case convertion algorithm.

from autoname import AutoName, transform
from enum import auto


@transform(function=str.lower)
class GameType(AutoName):
    INDIE = auto()


print(GameType.INDIE.value)  # "indie"

If the autoname is not a sound variable name. there are alias too.

  • StrEnum = AutoName
  • LowerStrEnum = AutoNameLower
  • UpperStrEnum = AutoNameUpper

e.g.

from autoname import StrEnum, transform
from enum import auto


class GameType(StrEnum):
    INDIE = auto()


print(GameType.INDIE.value)  # "INDIE"

Alternative

About

an enum `AutoName` from python docs with stringcase options

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages