Skip to content

Define null values for enums #6095

@ifsheldon

Description

@ifsheldon

🚀 Feature

Create null values for enums instead of using None. For example, utilities.enums.DistributedType should have a DistributedTypes.None enum value in addition to existing enum values.

Motivation

Python builtin None is hard to track, and I think it is always a good practice to have default null values for enums in compensation for the lack of null safety of Python. It is especially beneficial when a variable holding a type of enum will be None, which is the case for DistributedType in trainer.connectors.accelerator_connector.

Pitch

Define null values for enums, we can:

  • keep track of when a variable of a enum type will be None, facilitating code analysis
  • remind code collaborators of the possibility of being None when using an enum type
  • (If we practice this broadly, we can at least) ensure code collaborators that a variable holding a value of a enum type will always valid(i.e. not literally None)
  • "prevent" Null pointer exception/ None does not have method/attribute error.

Additional context

When fixing #5966 in #5970, I have to take special care of None of self._distrib_type, which is a bit annoying.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions