Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit 1f3641d

Browse files
committed
small fix
1 parent 8a8b51d commit 1f3641d

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

numba_typing/arguments_annotation_default_func_class.py

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

numba_typing/type_annotation.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from inspect import signature, getfullargspec
2+
from typing import get_type_hints
3+
4+
5+
def get_func_annotations(func):
6+
"""Get annotations and default values of the fuction parameters."""
7+
sig = signature(func)
8+
annotations = {}
9+
defaults = {}
10+
11+
for name, param in sig.parameters.items():
12+
if (param.annotation == sig.empty):
13+
raise SyntaxError
14+
15+
annotations[name] = param.annotation
16+
if (param.default != sig.empty):
17+
defaults[name] = param.default
18+
19+
return annotations, defaults
20+
21+
22+
def get_cls_annotations(cls):
23+
"""Get annotations of class attributes."""
24+
return get_type_hints(cls)
25+
26+
27+
if __name__ == '__main__':
28+
def foo(a: int, b: int = 3,):
29+
pass
30+
31+
print(get_func_annotations(foo))

0 commit comments

Comments
 (0)