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

[pre-commit.ci] pre-commit autoupdate #11

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
max-line-length = 99
max-complexity = 10
extend-ignore =
E203, # E203: Whitespace before ':' (violates PEP8 and black style)
A003, # A003: class attribute is shadowing a python builtin (we violate this on purpose a lot)
# E203: Whitespace before ':' (violates PEP8 and black style)
E203,
# A003: class attribute is shadowing a python builtin (we violate this on purpose a lot)
A003,
extend-exclude = */site-packages/*
18 changes: 9 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 8fe62d14e0b4d7d845a7022c5c2c3ae41bdd3f26 # frozen: v4.1.0
rev: 2c9f875913ee60ca25ce70243dc24d5b6415598c # frozen: v4.6.0
hooks:
- id: check-yaml
- id: check-toml
- repo: https://github.com/pre-commit/pygrep-hooks
rev: 6f51a66bba59954917140ec2eeeaa4d5e630e6ce # frozen: v1.9.0
rev: 3a6eb0fadf60b3cccfd80bad9dbb6fae7e47b316 # frozen: v1.10.0
hooks:
- id: python-use-type-annotations
- id: python-check-blanket-noqa
- repo: https://github.com/PyCQA/isort
rev: c5e8fa75dda5f764d20f66a215d71c21cfa198e1 # frozen: 5.10.1
rev: c235f5e450b4b84e58d114ed4c589cbf454175a3 # frozen: 5.13.2
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: ae2c0758c9e61a385df9700dc9c231bf54887041 # frozen: 22.3.0
rev: b965c2a5026f8ba399283ba3e01898b012853c79 # frozen: 24.8.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: cbeb4c9c4137cff1568659fcc48e8b85cddd0c8d # frozen: 4.0.1
rev: e43806be3607110919eff72939fda031776e885a # frozen: 7.1.1
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear
- flake8-builtins
- flake8-comprehensions
- repo: https://github.com/myint/docformatter
rev: 67919ee01837761f2d954d7fbb08c12cdd38ec5a # frozen: v1.4
- repo: https://github.com/PyCQA/docformatter
rev: dfefe062799848234b4cd60b04aa633c0608025e # frozen: v1.7.5
hooks:
- id: docformatter
- repo: https://github.com/executablebooks/mdformat
rev: b8c05ae822d53326e967da45367d0408afc56a81 # frozen: 0.7.14
rev: 08fba30538869a440b5059de90af03e3502e35fb # frozen: 0.7.17
hooks:
- id: mdformat
additional_dependencies:
- mdformat-black
- mdformat-toc
- repo: https://github.com/pre-commit/mirrors-mypy
rev: bdfdfda2221c4fd123dbc9ac0f2074951bd5af58 # frozen: v0.942
rev: d4911cfb7f1010759fde68da196036feeb25b99d # frozen: v1.11.2
hooks:
- id: mypy
args: ["--scripts-are-modules"]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ env = Env()
# A single validator function
NAME = env.str("NAME", validate=lambda n: n.startswith("Harry"))


# A validator function can signal error by raising an exception
def is_positive(num):
if num <= 0:
Expand Down
48 changes: 16 additions & 32 deletions src/typenv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,12 @@ def str(
*,
default: type[_Missing] | _Str = _Missing,
validate: Callable | Iterable[Callable] = (),
) -> _Str:
...
) -> _Str: ...

@typing.overload
def str(
self, name: _Str, *, default: None, validate: Callable | Iterable[Callable] = ()
) -> _Str | None:
...
) -> _Str | None: ...

def str(
self,
Expand All @@ -171,8 +169,7 @@ def bytes(
encoding: Literal["hex"],
default: type[_Missing] | _Bytes = _Missing,
validate: Callable | Iterable[Callable] = (),
) -> _Bytes:
...
) -> _Bytes: ...

@typing.overload
def bytes(
Expand All @@ -182,8 +179,7 @@ def bytes(
encoding: Literal["hex"],
default: None,
validate: Callable | Iterable[Callable] = (),
) -> _Bytes | None:
...
) -> _Bytes | None: ...

def bytes(
self,
Expand All @@ -202,14 +198,12 @@ def int(
*,
default: type[_Missing] | _Int = _Missing,
validate: Callable | Iterable[Callable] = (),
) -> _Int:
...
) -> _Int: ...

@typing.overload
def int(
self, name: _Str, *, default: None, validate: Callable | Iterable[Callable] = ()
) -> _Int | None:
...
) -> _Int | None: ...

def int(
self,
Expand All @@ -227,14 +221,12 @@ def bool(
*,
default: type[_Missing] | _Bool = _Missing,
validate: Callable | Iterable[Callable] = (),
) -> _Bool:
...
) -> _Bool: ...

@typing.overload
def bool(
self, name: _Str, *, default: None, validate: Callable | Iterable[Callable] = ()
) -> _Bool | None:
...
) -> _Bool | None: ...

def bool(
self,
Expand All @@ -252,14 +244,12 @@ def float(
*,
default: type[_Missing] | _Float = _Missing,
validate: Callable | Iterable[Callable] = (),
) -> _Float:
...
) -> _Float: ...

@typing.overload
def float(
self, name: _Str, *, default: None, validate: Callable | Iterable[Callable] = ()
) -> _Float | None:
...
) -> _Float | None: ...

def float(
self,
Expand All @@ -277,14 +267,12 @@ def decimal(
*,
default: type[_Missing] | D = _Missing,
validate: Callable | Iterable[Callable] = (),
) -> D:
...
) -> D: ...

@typing.overload
def decimal(
self, name: _Str, *, default: None, validate: Callable | Iterable[Callable] = ()
) -> D | None:
...
) -> D | None: ...

def decimal(
self,
Expand Down Expand Up @@ -314,14 +302,12 @@ def list(
*,
default: type[_Missing] | _List = _Missing,
validate: Callable | Iterable[Callable] = (),
) -> _List[_Str]:
...
) -> _List[_Str]: ...

@typing.overload
def list(
self, name: _Str, *, default: None, validate: Callable | Iterable[Callable] = ()
) -> _List[_Str] | None:
...
) -> _List[_Str] | None: ...

@typing.overload
def list(
Expand All @@ -331,8 +317,7 @@ def list(
default: type[_Missing] | _List[_T] = _Missing,
validate: Callable | Iterable[Callable] = (),
subcast: Callable[..., _T],
) -> _List[_T]:
...
) -> _List[_T]: ...

@typing.overload
def list(
Expand All @@ -342,8 +327,7 @@ def list(
default: None,
validate: Callable | Iterable[Callable] = (),
subcast: Callable[..., _T],
) -> _List[_T] | None:
...
) -> _List[_T] | None: ...

def list(
self,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def is_negative(val):
assert env.int("AN_INTEGER", validate=is_positive) == 982
assert env.int("AN_INTEGER", validate=(is_positive, is_positive)) == 982

with pytest.raises(Exception):
with pytest.raises(Exception, match="AN_INTEGER"):
env.int("AN_INTEGER", validate=is_negative)
with pytest.raises(Exception):
with pytest.raises(Exception, match="AN_INTEGER"):
env.int("AN_INTEGER", validate=(is_positive, is_negative))


Expand Down
Loading