Skip to content

Commit

Permalink
Add arguments to type hints (#56)
Browse files Browse the repository at this point in the history
* Add arguments to type hints

* Add pr link

* Use T consistently as instance of a config class
  • Loading branch information
hynek committed Apr 20, 2023
1 parent bd4067a commit 9c424b2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ Whenever there is a need to break compatibility, it is announced here in the cha

## [Unreleased](https://github.com/hynek/environ-config/compare/23.1.0...HEAD)

### Fixed

- Type hints for `environ.config()` now allow for arguments (e.g. `@environ.config(prefix="")`).
[#56](https://github.com/hynek/environ-config/issues/56)


## [23.1.0](https://github.com/hynek/environ-config/compare/22.1.0...23.1.0) - 2023-01-27

### Backwards-incompatible Changes
Expand Down
21 changes: 19 additions & 2 deletions src/environ/_environ_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import logging
import os

from typing import Any, Callable, TypeVar
from typing import Any, Callable, TypeVar, overload

import attr

Expand Down Expand Up @@ -60,13 +60,30 @@ class Raise:
T = TypeVar("T")


@overload
def config(
*,
prefix: str | Sentinel = PREFIX_NOT_SET,
from_environ: str = "from_environ",
generate_help: str = "generate_help",
frozen: bool = False,
) -> Callable[[type[T]], type[T]]:
...


@overload
def config(maybe_cls: type[T]) -> type[T]:
...


def config(
maybe_cls: type[T] | None = None,
*,
prefix: str | Sentinel = PREFIX_NOT_SET,
from_environ: str = "from_environ",
generate_help: str = "generate_help",
frozen: bool = False,
) -> T:
) -> type[T] | Callable[[type[T]], type[T]]:
"""
Make a class a configuration class.
Expand Down
10 changes: 10 additions & 0 deletions typing_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,13 @@ def takes_sub(s: Config.Sub) -> int:
ds: str = cfg.d_secret
vs: str = cfg.v_secret
as_: str = cfg.a_secret


@environ.config(prefix="")
class ConfigNoPrefix:
test_var = environ.var()


@environ.config()
class ConfigEmptyParens:
test_var = environ.var()

0 comments on commit 9c424b2

Please sign in to comment.