Skip to content

replace constant dicts with namedtuples #257

@smoors

Description

@smoors

this will be a life changing improvement that must get top priority.

example:

from typing import NamedTuple

class DeviceTypes(NamedTuple):
    CPU: str = 'cpu'
    GPU: str = 'gpu'

DEVICE_TYPES = DeviceTypes()

print(DEVICE_TYPES.GPU)  # 'gpu'

advantages:

  • really constant, you cannot change the value directly
  • you only have to import DEVICE_TYPES, not CPU or GPU
  • strings 'CPU' and 'GPU' don't have to be defined anymore
  • thus, you cannot mistakenly use the 'CPU' or 'GPU' strings anymore
  • easier syntax DEVICE_TYPES.CPU instead of DEVICE_TYPES[CPU]: saves a full character!

for SCALES this is probably not a good idea, as we really want to use the strings themselves, e.g. on the cmd line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions