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

Commit 77901db

Browse files
committed
add getting annotation for func and classes
1 parent 30e5395 commit 77901db

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from inspect import signature, getfullargspec
2+
from typing import get_type_hints
3+
4+
5+
def get_arguments_annotation_default_func(method):
6+
sig = signature(method)
7+
argspec = getfullargspec(method)
8+
arg_index=0
9+
annotations = {}
10+
defaults = {}
11+
12+
for arg in argspec.args:
13+
if (sig.parameters[arg].annotation == sig.empty):
14+
raise SyntaxError
15+
else:
16+
annotations[arg] = sig.parameters[arg].annotation
17+
for arg in argspec.args:
18+
if (sig.parameters[arg].default != sig.empty):
19+
defaults[arg] = sig.parameters[arg].default
20+
21+
return annotations, defaults
22+
23+
24+
def get_arguments_annotation_class(cls):
25+
return get_type_hints(cls)
26+

0 commit comments

Comments
 (0)