typeguard_ay 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,3 @@
1
+ from typeguard_ay.typeguard import TypeGuard, WrongTypeAnnotationError
2
+
3
+ __all__ = ["TypeGuard", "WrongTypeAnnotationError"]
@@ -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()
@@ -0,0 +1,47 @@
1
+ Metadata-Version: 2.4
2
+ Name: typeguard_ay
3
+ Version: 0.1.0
4
+ Summary: Keyword argument type checking decorator
5
+ Author: CemAyyildiz
6
+ Author-email: CemAyyildiz <ayyldz1925@gmail.com>
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+
12
+ # typeguard_ay
13
+
14
+ A decorator that checks the types of keyword arguments against a function's annotations.
15
+
16
+ ## Install
17
+
18
+ From the project folder:
19
+
20
+ ```bash
21
+ pip install .
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ```python
27
+ from typeguard_ay import TypeGuard, WrongTypeAnnotationError
28
+
29
+
30
+ @TypeGuard(label="Custom Type Guard")
31
+ def add(*, x: int, y: int) -> int:
32
+ return x + y
33
+
34
+
35
+ add(x=1, y=2) # 3
36
+
37
+ try:
38
+ add(x=1, y="2")
39
+ except WrongTypeAnnotationError as e:
40
+ print(e) # Argument 'y' must be of type int, but got str
41
+ ```
42
+
43
+ Only keyword arguments are checked.
44
+
45
+ ## Credits
46
+
47
+ `typeguard.py` comes from [canbula/PythonProgramming](https://github.com/canbula/PythonProgramming/tree/master/Week06) (MIT License, see `LICENSE`).
@@ -0,0 +1,6 @@
1
+ typeguard_ay/__init__.py,sha256=5plYV4COEjDmu9C05CxOihslJoHkHJpWAIm58B4gYl4,124
2
+ typeguard_ay/typeguard.py,sha256=p6WDUlDWCa6RZOW7LEFtjDWsMBS9x1cS00NQTmtttrw,1225
3
+ typeguard_ay-0.1.0.dist-info/licenses/LICENSE,sha256=gvxLFWHNnk_Z-87pKfEVwOMV4nCeVhr86gYO-LQ0IcY,1069
4
+ typeguard_ay-0.1.0.dist-info/WHEEL,sha256=y6e-a5KI2W-qDAJKfh9Xr81bin8NgUdfWgz3VSXXpe4,80
5
+ typeguard_ay-0.1.0.dist-info/METADATA,sha256=DRFBQgwhUtFjXVEdFVnk51qy822L-iT2dhVENiJ39pI,980
6
+ typeguard_ay-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: uv 0.12.9
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Bora Canbula
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.