Skip to content

Commit 2ab9764

Browse files
committed
Fix mypy for validate arg (only py3.8+)
1 parent 0c543f1 commit 2ab9764

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ repos:
1515
rev: v0.910
1616
hooks:
1717
- id: mypy
18-
args: [--strict]
18+
args: [--strict, --show-error-codes]
1919
- repo: https://github.com/ambv/black
2020
rev: 21.6b0
2121
hooks:

ecs_logging/_stdlib.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ def __init__(
7676
fmt=None,
7777
datefmt=None,
7878
style="%",
79-
validate=True,
79+
validate=None,
8080
stack_trace_limit=None,
8181
exclude_fields=(),
8282
):
83-
# type: (Any, Optional[str], Optional[str], str, bool, Optional[int], Sequence[str]) -> None
83+
# type: (Any, Optional[str], Optional[str], str, Optional[bool], Optional[int], Sequence[str]) -> None
8484
"""Initialize the ECS formatter.
8585
8686
:param int stack_trace_limit:
@@ -99,8 +99,12 @@ def __init__(
9999
100100
exclude_keys=["error"]
101101
"""
102+
_kwargs = {}
103+
if validate is not None:
104+
# validate was introduced in py3.8 so we need to only provide it if the user provided it
105+
_kwargs["validate"] = validate
102106
super(StdlibFormatter, self).__init__(
103-
fmt=fmt, datefmt=datefmt, style=style, validate=validate
107+
fmt=fmt, datefmt=datefmt, style=style, **_kwargs
104108
)
105109

106110
if stack_trace_limit is not None:

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ def lint(session):
5050
session.install("flake8", "black", "mypy")
5151
session.run("black", "--check", "--target-version=py27", *SOURCE_FILES)
5252
session.run("flake8", "--ignore=E501,W503", *SOURCE_FILES)
53-
session.run("mypy", "--strict", "ecs_logging/")
53+
session.run("mypy", "--strict", "--show-error-codes", "ecs_logging/")

0 commit comments

Comments
 (0)