typeguard-kubilay 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.
- typeguard_kubilay-0.1.0/LICENSE +21 -0
- typeguard_kubilay-0.1.0/PKG-INFO +54 -0
- typeguard_kubilay-0.1.0/README.md +40 -0
- typeguard_kubilay-0.1.0/pyproject.toml +23 -0
- typeguard_kubilay-0.1.0/setup.cfg +4 -0
- typeguard_kubilay-0.1.0/src/typeguard_kubilay/__init__.py +6 -0
- typeguard_kubilay-0.1.0/src/typeguard_kubilay/__main__.py +24 -0
- typeguard_kubilay-0.1.0/src/typeguard_kubilay/core.py +52 -0
- typeguard_kubilay-0.1.0/src/typeguard_kubilay.egg-info/PKG-INFO +54 -0
- typeguard_kubilay-0.1.0/src/typeguard_kubilay.egg-info/SOURCES.txt +11 -0
- typeguard_kubilay-0.1.0/src/typeguard_kubilay.egg-info/dependency_links.txt +1 -0
- typeguard_kubilay-0.1.0/src/typeguard_kubilay.egg-info/entry_points.txt +2 -0
- typeguard_kubilay-0.1.0/src/typeguard_kubilay.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
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.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: typeguard_kubilay
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Fonksiyon argümanlarını tip açıklamalarına göre denetleyen basit bir dekoratör
|
|
5
|
+
Author: Kubilay
|
|
6
|
+
License: MIT
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# typeguard_kubilay
|
|
16
|
+
|
|
17
|
+
Fonksiyon argümanlarını tip açıklamalarına (type annotations) göre çalışma anında denetleyen basit bir dekoratör.
|
|
18
|
+
|
|
19
|
+
## Kurulum
|
|
20
|
+
|
|
21
|
+
Proje klasöründe:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install .
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Geliştirme (düzenlenebilir) modunda:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install -e .
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Kullanım
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from typeguard_kubilay import TypeGuard, WrongTypeAnnotationError
|
|
37
|
+
|
|
38
|
+
@TypeGuard(label="Custom Type Guard")
|
|
39
|
+
def add(*, x: int, y: int) -> int:
|
|
40
|
+
return x + y
|
|
41
|
+
|
|
42
|
+
add(x=6, y=4) # 10
|
|
43
|
+
add(x=6, y="Canbula") # WrongTypeAnnotationError
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Ekrana bilgi yazdırmadan kullanmak için: `@TypeGuard(verbose=False)`.
|
|
47
|
+
|
|
48
|
+
## Demo
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
typeguard-kubilay-demo
|
|
52
|
+
# veya
|
|
53
|
+
python -m typeguard_kubilay
|
|
54
|
+
```
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# typeguard_kubilay
|
|
2
|
+
|
|
3
|
+
Fonksiyon argümanlarını tip açıklamalarına (type annotations) göre çalışma anında denetleyen basit bir dekoratör.
|
|
4
|
+
|
|
5
|
+
## Kurulum
|
|
6
|
+
|
|
7
|
+
Proje klasöründe:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install .
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Geliştirme (düzenlenebilir) modunda:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install -e .
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Kullanım
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from typeguard_kubilay import TypeGuard, WrongTypeAnnotationError
|
|
23
|
+
|
|
24
|
+
@TypeGuard(label="Custom Type Guard")
|
|
25
|
+
def add(*, x: int, y: int) -> int:
|
|
26
|
+
return x + y
|
|
27
|
+
|
|
28
|
+
add(x=6, y=4) # 10
|
|
29
|
+
add(x=6, y="Canbula") # WrongTypeAnnotationError
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Ekrana bilgi yazdırmadan kullanmak için: `@TypeGuard(verbose=False)`.
|
|
33
|
+
|
|
34
|
+
## Demo
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
typeguard-kubilay-demo
|
|
38
|
+
# veya
|
|
39
|
+
python -m typeguard_kubilay
|
|
40
|
+
```
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "typeguard_kubilay"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Fonksiyon argümanlarını tip açıklamalarına göre denetleyen basit bir dekoratör"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "Kubilay" }]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"License :: OSI Approved :: MIT License",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.scripts]
|
|
20
|
+
typeguard-kubilay-demo = "typeguard_kubilay.__main__:main"
|
|
21
|
+
|
|
22
|
+
[tool.setuptools.packages.find]
|
|
23
|
+
where = ["src"]
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""Demo: `python -m typeguard_kubilay` veya `typeguard-kubilay-demo`."""
|
|
2
|
+
|
|
3
|
+
from .core import TypeGuard
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@TypeGuard(label="Custom Type Guard")
|
|
7
|
+
def add(*, x: int, y: int) -> int:
|
|
8
|
+
return x + y
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def main():
|
|
12
|
+
x = 6
|
|
13
|
+
y = "Canbula"
|
|
14
|
+
try:
|
|
15
|
+
result = add(x=x, y=y)
|
|
16
|
+
print(f"Result: {result}")
|
|
17
|
+
except TypeError as e:
|
|
18
|
+
print(f"TypeError: {e}")
|
|
19
|
+
except Exception as e:
|
|
20
|
+
print(f"Error ({e.__class__.__name__}): {e}")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
if __name__ == "__main__":
|
|
24
|
+
main()
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""TypeGuard dekoratörü ve ilgili hata sınıfı."""
|
|
2
|
+
|
|
3
|
+
import functools
|
|
4
|
+
import inspect
|
|
5
|
+
|
|
6
|
+
__all__ = ["WrongTypeAnnotationError", "TypeGuard"]
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class WrongTypeAnnotationError(TypeError):
|
|
10
|
+
"""Bir argüman, tip açıklamasıyla (annotation) uyuşmadığında fırlatılır."""
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class TypeGuard:
|
|
14
|
+
"""Fonksiyon argümanlarını tip açıklamalarına göre çalışma anında denetler.
|
|
15
|
+
|
|
16
|
+
Örnek:
|
|
17
|
+
>>> @TypeGuard(label="Custom Type Guard")
|
|
18
|
+
... def add(*, x: int, y: int) -> int:
|
|
19
|
+
... return x + y
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def __init__(self, label: str = "TypeGuard", verbose: bool = True):
|
|
23
|
+
self.label = label
|
|
24
|
+
self.verbose = verbose
|
|
25
|
+
|
|
26
|
+
def __call__(self, func):
|
|
27
|
+
annotations = {
|
|
28
|
+
k: v for k, v in func.__annotations__.items() if k != "return"
|
|
29
|
+
}
|
|
30
|
+
signature = inspect.signature(func)
|
|
31
|
+
|
|
32
|
+
@functools.wraps(func)
|
|
33
|
+
def wrapper(*args, **kwargs):
|
|
34
|
+
if self.verbose:
|
|
35
|
+
print(f"{self.label}: Type checking")
|
|
36
|
+
print(f"Function: {func.__name__}")
|
|
37
|
+
print(f"Type annotations: {func.__annotations__}")
|
|
38
|
+
|
|
39
|
+
# Hem konumsal hem anahtar kelimeli argümanları parametre adlarına eşle
|
|
40
|
+
bound = signature.bind(*args, **kwargs)
|
|
41
|
+
for name, expected in annotations.items():
|
|
42
|
+
if name in bound.arguments and isinstance(expected, type):
|
|
43
|
+
value = bound.arguments[name]
|
|
44
|
+
if not isinstance(value, expected):
|
|
45
|
+
raise WrongTypeAnnotationError(
|
|
46
|
+
f"Argument '{name}' must be of type "
|
|
47
|
+
f"{expected.__name__}, but got "
|
|
48
|
+
f"{type(value).__name__}"
|
|
49
|
+
)
|
|
50
|
+
return func(*args, **kwargs)
|
|
51
|
+
|
|
52
|
+
return wrapper
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: typeguard_kubilay
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Fonksiyon argümanlarını tip açıklamalarına göre denetleyen basit bir dekoratör
|
|
5
|
+
Author: Kubilay
|
|
6
|
+
License: MIT
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# typeguard_kubilay
|
|
16
|
+
|
|
17
|
+
Fonksiyon argümanlarını tip açıklamalarına (type annotations) göre çalışma anında denetleyen basit bir dekoratör.
|
|
18
|
+
|
|
19
|
+
## Kurulum
|
|
20
|
+
|
|
21
|
+
Proje klasöründe:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install .
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Geliştirme (düzenlenebilir) modunda:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install -e .
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Kullanım
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from typeguard_kubilay import TypeGuard, WrongTypeAnnotationError
|
|
37
|
+
|
|
38
|
+
@TypeGuard(label="Custom Type Guard")
|
|
39
|
+
def add(*, x: int, y: int) -> int:
|
|
40
|
+
return x + y
|
|
41
|
+
|
|
42
|
+
add(x=6, y=4) # 10
|
|
43
|
+
add(x=6, y="Canbula") # WrongTypeAnnotationError
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Ekrana bilgi yazdırmadan kullanmak için: `@TypeGuard(verbose=False)`.
|
|
47
|
+
|
|
48
|
+
## Demo
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
typeguard-kubilay-demo
|
|
52
|
+
# veya
|
|
53
|
+
python -m typeguard_kubilay
|
|
54
|
+
```
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/typeguard_kubilay/__init__.py
|
|
5
|
+
src/typeguard_kubilay/__main__.py
|
|
6
|
+
src/typeguard_kubilay/core.py
|
|
7
|
+
src/typeguard_kubilay.egg-info/PKG-INFO
|
|
8
|
+
src/typeguard_kubilay.egg-info/SOURCES.txt
|
|
9
|
+
src/typeguard_kubilay.egg-info/dependency_links.txt
|
|
10
|
+
src/typeguard_kubilay.egg-info/entry_points.txt
|
|
11
|
+
src/typeguard_kubilay.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
typeguard_kubilay
|