Skip to content

Commit e66df11

Browse files
fix ruff lints
1 parent 0102ba1 commit e66df11

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+621
-760
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
- removed decorator `@timer_class`
1010
- removed decorator `@uminplemented`
1111
- removed decorator `@trace_if_returns`
12+
- removed `enable_pedantic, disable_pedantic, is_enabled`
1213
- removed `GenericMixin.type_var`. Use `GenericMixin.type_vars` instead.
1314
- added `Taskfile.yml` and use it in CI
1415
- removed `create_pdoc.sh`
15-
- moved `examples` out of the package
16+
- removed `examples`
1617
- CI: added a check that `CHANGELOG.md` is modified on feature branches
1718
- CI: added a check that the poetry package version was updated
1819
- added `ruff` linter and apply lint rules to code

Taskfile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ tasks:
3333
desc: Runs the linter (ruff)
3434
silent: true
3535
cmds:
36-
- ruff check pedantic
36+
- ruff check pedantic tests
3737

3838
lint-fix:
3939
desc: Runs the linter and fixes all fixable errors automatically

examples/config.csv

Lines changed: 0 additions & 2 deletions
This file was deleted.

examples/validate.py

Lines changed: 0 additions & 87 deletions
This file was deleted.

pedantic/__init__.py

Lines changed: 125 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,132 @@
11
from pedantic.decorators import (
2-
overrides, trace,
2+
calculate_in_subprocess,
33
deprecated,
4+
for_all_methods,
5+
frozen_dataclass,
6+
frozen_type_safe_dataclass,
7+
in_subprocess,
8+
overrides,
49
pedantic,
5-
pedantic_require_docstring, for_all_methods, trace_class, pedantic_class,
6-
pedantic_class_require_docstring, frozen_dataclass, frozen_type_safe_dataclass, in_subprocess,
7-
calculate_in_subprocess, retry
10+
pedantic_class,
11+
pedantic_class_require_docstring,
12+
pedantic_require_docstring,
13+
retry,
14+
trace,
15+
trace_class,
16+
)
17+
from pedantic.decorators.fn_deco_validate.exceptions import (
18+
ConversionError,
19+
InvalidHeader,
20+
ParameterException,
21+
TooManyArguments,
22+
ValidateException,
23+
ValidatorException,
24+
)
25+
from pedantic.decorators.fn_deco_validate.fn_deco_validate import (
26+
ReturnAs,
27+
validate,
28+
)
29+
from pedantic.decorators.fn_deco_validate.parameters import (
30+
Deserializable,
31+
EnvironmentVariableParameter,
32+
ExternalParameter,
33+
Parameter,
34+
)
35+
from pedantic.decorators.fn_deco_validate.validators import (
36+
Composite,
37+
DatetimeIsoFormat,
38+
DateTimeUnixTimestamp,
39+
Email,
40+
ForEach,
41+
IsEnum,
42+
IsUuid,
43+
MatchPattern,
44+
Max,
45+
MaxLength,
46+
Min,
47+
MinLength,
48+
NotEmpty,
49+
Validator,
50+
)
51+
from pedantic.mixins import (
52+
DecoratorType,
53+
GenericMixin,
54+
WithDecoratedMethods,
55+
create_decorator,
56+
)
57+
from pedantic.type_checking_logic import (
58+
assert_value_matches_type,
59+
resolve_forward_ref,
860
)
961

10-
from pedantic.mixins import GenericMixin, create_decorator, DecoratorType, WithDecoratedMethods
11-
12-
from pedantic.type_checking_logic import assert_value_matches_type, resolve_forward_ref
62+
__all__ = [
63+
'Composite',
64+
'ConversionError',
65+
'DateTimeUnixTimestamp',
66+
'DatetimeIsoFormat',
67+
'DecoratorType',
68+
'Deserializable',
69+
'Email',
70+
'EnvironmentVariableParameter',
71+
'ExternalParameter',
72+
'ForEach',
73+
'GenericMixin',
74+
'InvalidHeader',
75+
'IsEnum',
76+
'IsUuid',
77+
'MatchPattern',
78+
'Max',
79+
'MaxLength',
80+
'Min',
81+
'MinLength',
82+
'NotEmpty',
83+
'Parameter',
84+
'ParameterException',
85+
'ReturnAs',
86+
'TooManyArguments',
87+
'ValidateException',
88+
'Validator',
89+
'ValidatorException',
90+
'WithDecoratedMethods',
91+
'assert_value_matches_type',
92+
'calculate_in_subprocess',
93+
'create_decorator',
94+
'deprecated',
95+
'for_all_methods',
96+
'frozen_dataclass',
97+
'frozen_type_safe_dataclass',
98+
'in_subprocess',
99+
'overrides',
100+
'pedantic',
101+
'pedantic_class',
102+
'pedantic_class_require_docstring',
103+
'pedantic_require_docstring',
104+
'resolve_forward_ref',
105+
'retry',
106+
'trace',
107+
'trace_class',
108+
'validate',
109+
]
13110

14-
from pedantic.env_var_logic import disable_pedantic, enable_pedantic, is_enabled
111+
try:
112+
from pedantic.decorators.fn_deco_validate.parameters import (
113+
FlaskFormParameter,
114+
FlaskGetParameter,
115+
FlaskHeaderParameter,
116+
FlaskJsonParameter,
117+
FlaskParameter,
118+
FlaskPathParameter,
119+
GenericFlaskDeserializer,
120+
)
15121

16-
from pedantic.decorators.fn_deco_validate.fn_deco_validate import validate, ReturnAs
17-
from pedantic.decorators.fn_deco_validate.exceptions import *
18-
from pedantic.decorators.fn_deco_validate.parameters import *
19-
from pedantic.decorators.fn_deco_validate.validators import *
122+
__all__ +=[
123+
'FlaskFormParameter',
124+
'FlaskGetParameter',
125+
'FlaskHeaderParameter',
126+
'FlaskJsonParameter',
127+
'FlaskParameter',
128+
'FlaskPathParameter',
129+
'GenericFlaskDeserializer',
130+
]
131+
except ImportError:
132+
pass # no Flask installed

pedantic/decorators/class_decorators.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
from dataclasses import is_dataclass
55

66
from pedantic.constants import TYPE_VAR_ATTR_NAME, TYPE_VAR_METHOD_NAME, TYPE_VAR_SELF, C, F
7-
from pedantic.decorators.fn_deco_trace import trace
87
from pedantic.decorators.fn_deco_pedantic import pedantic, pedantic_require_docstring
9-
from pedantic.env_var_logic import is_enabled
8+
from pedantic.decorators.fn_deco_trace import trace
109
from pedantic.exceptions import PedanticTypeCheckException
1110
from pedantic.type_checking_logic.check_generic_classes import (
1211
check_instance_of_generic_class_and_get_type_vars,
@@ -25,9 +24,6 @@ def for_all_methods(decorator: F) -> Callable[[type[C]], type[C]]:
2524
... def m2(self, x): pass
2625
"""
2726
def decorate(cls: C) -> C:
28-
if not is_enabled():
29-
return cls
30-
3127
if issubclass(cls, enum.Enum):
3228
raise PedanticTypeCheckException(f'Enum "{cls}" cannot be decorated with "@pedantic_class". '
3329
f'Enums are not supported yet.')

pedantic/decorators/fn_deco_pedantic.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from typing import Any
33

44
from pedantic.constants import F, ReturnType
5-
from pedantic.env_var_logic import is_enabled
65
from pedantic.get_context import get_context
76
from pedantic.models.decorated_function import DecoratedFunction
87
from pedantic.models.function_call import FunctionCall
@@ -46,9 +45,6 @@ def pedantic(func: F | None = None, require_docstring: bool = False) -> F:
4645
"""
4746

4847
def decorator(f: F) -> F:
49-
if not is_enabled():
50-
return f
51-
5248
decorated_func = DecoratedFunction(func=f)
5349

5450
if decorated_func.docstring is not None and (require_docstring or len(decorated_func.docstring.params)) > 0:

pedantic/decorators/fn_deco_validate/parameters/__init__.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
from .deserializable import Deserializable
44
from .environment_variable_parameter import EnvironmentVariableParameter
55

6+
__all__ = [
7+
'Deserializable',
8+
'EnvironmentVariableParameter',
9+
'ExternalParameter',
10+
'Parameter',
11+
]
12+
613
try:
714
from .flask_parameters import (
815
FlaskFormParameter,
@@ -14,19 +21,14 @@
1421
GenericFlaskDeserializer,
1522
)
1623

17-
__all__ = [
18-
'Deserializable',
19-
'EnvironmentVariableParameter',
20-
'ExternalParameter',
24+
__all__ += [
2125
'FlaskFormParameter',
2226
'FlaskGetParameter',
2327
'FlaskHeaderParameter',
2428
'FlaskJsonParameter',
2529
'FlaskParameter',
2630
'FlaskPathParameter',
2731
'GenericFlaskDeserializer',
28-
'Parameter',
2932
]
3033
except ImportError:
31-
pass
32-
34+
pass # no Flask installed

pedantic/decorators/fn_deco_validate/validators/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
'Email',
2121
'ForEach',
2222
'IsEnum',
23-
'IsEnum',
2423
'IsUuid',
2524
'MatchPattern',
2625
'Max',

pedantic/env_var_logic.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)