type-guard-venus 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- type_guard_venus-0.1.0/PKG-INFO +6 -0
- type_guard_venus-0.1.0/README.md +0 -0
- type_guard_venus-0.1.0/pyproject.toml +14 -0
- type_guard_venus-0.1.0/setup.cfg +4 -0
- type_guard_venus-0.1.0/src/type_guard_venus.egg-info/PKG-INFO +6 -0
- type_guard_venus-0.1.0/src/type_guard_venus.egg-info/SOURCES.txt +8 -0
- type_guard_venus-0.1.0/src/type_guard_venus.egg-info/dependency_links.txt +1 -0
- type_guard_venus-0.1.0/src/type_guard_venus.egg-info/top_level.txt +1 -0
- type_guard_venus-0.1.0/src/typeguard_venus/__init__.py +1 -0
- type_guard_venus-0.1.0/src/typeguard_venus/typeguard.py +45 -0
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "type_guard_venus"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Typeguard paketi"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
dependencies = []
|
|
12
|
+
|
|
13
|
+
[tool.setuptools.packages.find]
|
|
14
|
+
where = ["src"]
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
src/type_guard_venus.egg-info/PKG-INFO
|
|
4
|
+
src/type_guard_venus.egg-info/SOURCES.txt
|
|
5
|
+
src/type_guard_venus.egg-info/dependency_links.txt
|
|
6
|
+
src/type_guard_venus.egg-info/top_level.txt
|
|
7
|
+
src/typeguard_venus/__init__.py
|
|
8
|
+
src/typeguard_venus/typeguard.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
typeguard_venus
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .typeguard import *
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
class WrongTypeAnnotationError(TypeError):
|
|
2
|
+
pass
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class TypeGuard:
|
|
6
|
+
def __init__(self, label: str = "TypeGuard"):
|
|
7
|
+
self.label = label
|
|
8
|
+
|
|
9
|
+
def __call__(self, func):
|
|
10
|
+
def wrapper(*args, **kwargs):
|
|
11
|
+
print(f"{self.label}: Type checking")
|
|
12
|
+
print(f"Function: {func.__name__}")
|
|
13
|
+
print(f"Type annotations: {func.__annotations__}")
|
|
14
|
+
for k, v in func.__annotations__.items():
|
|
15
|
+
if k in kwargs:
|
|
16
|
+
if not isinstance(kwargs[k], v):
|
|
17
|
+
raise WrongTypeAnnotationError(
|
|
18
|
+
f"Argument '{k}' must be of type {v.__name__}, "
|
|
19
|
+
f"but got {type(kwargs[k]).__name__}"
|
|
20
|
+
)
|
|
21
|
+
result = func(*args, **kwargs)
|
|
22
|
+
return result
|
|
23
|
+
|
|
24
|
+
return wrapper
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@TypeGuard(label="Custom Type Guard")
|
|
28
|
+
def add(*, x: int, y: int) -> int:
|
|
29
|
+
return x + y
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def main():
|
|
33
|
+
x = 6
|
|
34
|
+
y = "Canbula"
|
|
35
|
+
try:
|
|
36
|
+
result = add(x=x, y=y)
|
|
37
|
+
print(f"Result: {result}")
|
|
38
|
+
except TypeError as e:
|
|
39
|
+
print(f"TypeError: {e}")
|
|
40
|
+
except Exception as e:
|
|
41
|
+
print(f"Error ({e.__class__.__name__}): {e}")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
if __name__ == "__main__":
|
|
45
|
+
main()
|