Skip to content

Commit

Permalink
Release 1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-makowski committed Apr 2, 2024
1 parent c64da08 commit 08d8d24
Show file tree
Hide file tree
Showing 11 changed files with 1,057 additions and 453 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
/__pycache__/
*/__pycache__
*.egg-info
*.pyc
**/.idea
*.pyc
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Nesting is allowed as long as the nested items are iterables (e.g. `typing.List`

Variables without an annotation for type are not enforced.

Note: Type Enforced does not support `__future__.annotations`. If you call `from __future__ import annotations` in your file, type enforced will not work as expected.

## Supported Type Checking Features:

- Function/Method Input Typing
Expand Down
Binary file added dist/type_enforced-1.5.0-py3-none-any.whl
Binary file not shown.
Binary file added dist/type_enforced-1.5.0.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/search.js

Large diffs are not rendered by default.

710 changes: 366 additions & 344 deletions docs/type_enforced/enforcer.html

Large diffs are not rendered by default.

754 changes: 669 additions & 85 deletions docs/type_enforced/utils.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "type_enforced"
version = "1.4.0"
version = "1.5.0"
description = "A pure python type enforcer for python type annotations"
authors = [
{name="Connor Makowski", email="[email protected]"}
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = type_enfoced
version = 1.4.0
version = 1.5.0
description_file = README.md

[options]
Expand Down
2 changes: 1 addition & 1 deletion test/test_fn_16.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

CustomConstraint = GenericConstraint(
{
'in_rgb': lambda x: x in ['red', 'green', 'blue'],
"in_rgb": lambda x: x in ["red", "green", "blue"],
}
)

Expand Down
33 changes: 15 additions & 18 deletions type_enforced/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def __getFnArity__(self):
)
return self.__fn__.__code__.co_argcount - extra_method_input_count


class GenericConstraint:
def __init__(self, constraints: dict):
"""
Expand All @@ -97,7 +98,9 @@ def __init__(self, constraints: dict):
- Note: All values in the dictionary must be functions that take a single argument and return a boolean.
- Note: The dictionary keys will be used to identify the failed constraints in the error messages.
"""
assert all(hasattr(v, '__call__') for v in constraints.values()), "All constraints must be functions."
assert all(
hasattr(v, "__call__") for v in constraints.values()
), "All constraints must be functions."
self.__constraint_checks__ = constraints

def __validate__(self, varname, value):
Expand All @@ -109,6 +112,7 @@ def __validate__(self, varname, value):
return f"An exception was raised when checking the constraint `{check_name}` with the provided value `{value}`. Error: {e}"
return True


class Constraint(GenericConstraint):
def __init__(
self,
Expand Down Expand Up @@ -165,7 +169,8 @@ def __init__(
- Default: None
"""
assert any(
v is not None for v in [pattern, gt, lt, ge, le, eq, ne, includes, excludes]
v is not None
for v in [pattern, gt, lt, ge, le, eq, ne, includes, excludes]
), "At least one constraint must be provided."
assert isinstance(
includes, (list, tuple, set, type(None))
Expand Down Expand Up @@ -199,25 +204,19 @@ def __init__(
self.__constraint_checks__["be a string"] = lambda x: isinstance(
x, str
)
self.__constraint_checks__[
"Regex Pattern Match"
] = lambda x: bool(re.findall(pattern, x))
self.__constraint_checks__["Regex Pattern Match"] = lambda x: bool(
re.findall(pattern, x)
)
if includes is not None:
self.__constraint_checks__[
f"Includes"
] = lambda x: x in includes
self.__constraint_checks__[f"Includes"] = lambda x: x in includes
if excludes is not None:
self.__constraint_checks__[
"Excludes"
] = lambda x: x not in excludes
self.__constraint_checks__["Excludes"] = lambda x: x not in excludes
if gt is not None:
self.__constraint_checks__[f"Greater Than ({gt})"] = (
lambda x: x > gt
)
if lt is not None:
self.__constraint_checks__[f"Less Than ({lt})"] = (
lambda x: x < lt
)
self.__constraint_checks__[f"Less Than ({lt})"] = lambda x: x < lt
if ge is not None:
self.__constraint_checks__[f"Greater Than Or Equal To ({ge})"] = (
lambda x: x >= ge
Expand All @@ -227,10 +226,8 @@ def __init__(
lambda x: x <= le
)
if eq is not None:
self.__constraint_checks__[f"Equal To ({eq})"] = (
lambda x: x == eq
)
self.__constraint_checks__[f"Equal To ({eq})"] = lambda x: x == eq
if ne is not None:
self.__constraint_checks__[f"Not Equal To ({ne})"] = (
lambda x: x != ne
)
)

0 comments on commit 08d8d24

Please sign in to comment.