Skip to content

Commit

Permalink
Fix typing for Env.enum; document by_value (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
sloria authored Jan 10, 2025
1 parent d175948 commit 0862487
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Features:
Thanks [arthurc0102](https://github.com/sloria/environs/issues/384)
for the suggestion.

Bug fixes:

- Typing: Fix typing for `Env.enum` to allow `by_value` to be passed ([#386](https://github.com/sloria/environs/issues/386)).

## 14.0.0 (2025-06-07)

Features:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ The following are all type-casting methods of `Env`:
- `env.log_level`
- `env.path` (casts to a [`pathlib.Path`](https://docs.python.org/3/library/pathlib.html))
- `env.enum` (casts to any given enum type specified in `enum` keyword argument)
- Pass `by_value=True` to parse and validate by the Enum's values.

## Reading `.env` files

Expand Down
6 changes: 5 additions & 1 deletion src/environs/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.. warning::
This module is provisional. Types may be modified, added, and removed between minor releases.
This module is private. Types may be modified, added, and removed between minor releases.
"""

from __future__ import annotations
Expand All @@ -16,6 +16,7 @@
from typing_extensions import Unpack

import marshmallow as ma
from marshmallow.fields import Field

T = typing.TypeVar("T")
EnumT = typing.TypeVar("EnumT", bound=enum.Enum)
Expand Down Expand Up @@ -137,6 +138,7 @@ def __call__(
default: None = ...,
*,
enum: type[EnumT],
by_value: bool | Field | type[Field] = ...,
**kwargs: Unpack[BaseMethodKwargs],
) -> EnumT | None: ...

Expand All @@ -147,6 +149,7 @@ def __call__(
default: EnumT = ...,
*,
enum: type[EnumT],
by_value: bool | Field | type[Field] = ...,
**kwargs: Unpack[BaseMethodKwargs],
) -> EnumT: ...

Expand All @@ -156,5 +159,6 @@ def __call__(
default: EnumT | None = ...,
*,
enum: type[EnumT],
by_value: bool | Field | type[Field] = False,
**kwargs: Unpack[BaseMethodKwargs],
) -> EnumT | None: ...

0 comments on commit 0862487

Please sign in to comment.