Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📝 Add documentation for enums created via the functional API #398

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
13 changes: 13 additions & 0 deletions docs/tutorial/parameter-types/enum.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,16 @@ Training neural network of type: lstm
```

</div>


### Functional API

In order to use an `Enum` created using the <a href="https://docs.python.org/3/library/enum.html#functional-api" class="external-link" target="_blank">functional API</a>, you need to create an enum with string values.

You also need to supply the default value as a string (not the enum):

```Python hl_lines="5 9"
{!../docs_src/parameter_types/enum/tutorial003.py!}
```

Alternatively, you can create an `Enum` that extends both `str` and `Enum`. In Python 3.11+, there is <a href="https://docs.python.org/3.11/library/enum.html#enum.StrEnum" class="external-link" target="_blank">`enum.StrEnum`</a>. For Python 3.10 or earlier, there is the <a href="https://github.com/irgeek/StrEnum" class="external-link" target="_blank">StrEnum package</a>.
13 changes: 13 additions & 0 deletions docs_src/parameter_types/enum/tutorial003.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from enum import Enum

import typer

NeuralNetwork = Enum("NeuralNetwork", {k: k for k in ["simple", "conv", "lstm"]})


def main(network: NeuralNetwork = typer.Option("simple", case_sensitive=False)):
typer.echo(f"Training neural network of type: {network.value}")


if __name__ == "__main__":
typer.run(main)