Skip to content

Commit 6cc9ff3

Browse files
committed
codacy linting
1 parent c2593d8 commit 6cc9ff3

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

‎.pre-commit-config.yaml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ repos:
3838
- platformdirs
3939
- PyYAML
4040
- toml
41+
- repo: https://github.com/PyCQA/bandit
42+
rev: '1.9.4'
43+
hooks:
44+
- id: bandit
45+
args: [-c, pyproject.toml]
4146
- repo: https://github.com/PyCQA/flake8
4247
rev: 7.3.0
4348
hooks:

‎envwrap/__init__.py‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Override parameter defaults via environment variables & config files."""
12
import logging
23
import os
34
from functools import partial, partialmethod
@@ -49,7 +50,7 @@ def read_config(fpath: PurePath) -> dict:
4950

5051
@cache
5152
def get_defaults(name: str, app: str, func: str):
52-
"""in-memory (functools.cache) of overrides extracted from config files & env vars"""
53+
"""In-memory (functools.cache) of overrides extracted from config files & env vars."""
5354
conf = PlatformDirs(name, False)
5455
overrides = {}
5556
for pth, base in (
@@ -76,8 +77,8 @@ def get_defaults(name: str, app: str, func: str):
7677
# func.a,a
7778
if func in cfg:
7879
overrides.update(cfg[func])
79-
except Exception:
80-
pass
80+
except Exception as exc:
81+
log.debug(f"ignored Exception: {exc}")
8182
overrides.update((k[len(prefix):].lower(), v)
8283
for prefix in (f"{name}_".upper(), f"{name}_{app}_".upper(),
8384
f"{name}_{func}_".upper(), f"{name}_{app}_{func}_".upper())
@@ -86,8 +87,8 @@ def get_defaults(name: str, app: str, func: str):
8687

8788

8889
def envwrap(name: str, app: str = "", types: dict = None, is_method=False):
89-
"""
90-
Override parameter defaults via environment variables & config files.
90+
"""Function decorator overriding default arguments.
91+
9192
Precedence (descending):
9293
9394
- call (`func(a=3)`)
@@ -124,6 +125,7 @@ def envwrap(name: str, app: str = "", types: dict = None, is_method=False):
124125
...
125126
>>> test(c=99)
126127
received: a=42, b=2, c=99
128+
127129
"""
128130
if types is None:
129131
types = {}
@@ -147,7 +149,7 @@ def wrap(func):
147149
try:
148150
overrides[k] = typ(overrides[k])
149151
except Exception:
150-
pass
152+
log.debug("Failed to convert %s to %s", overrides[k], typ)
151153
else:
152154
break
153155
elif param.default is not None: # type of default value

‎pyproject.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ dev = ["pytest>=6", "pytest-cov", "toml"]
4646
[project.scripts]
4747
envwrap = "envwrap.cli:main"
4848

49+
[tool.bandit]
50+
exclude_dirs = ["tests"]
51+
4952
[tool.flake8]
5053
max_line_length = 99
5154
extend_ignore = ["E261"]

0 commit comments

Comments
 (0)