I'm trying to implement strong type genetic programming in python.
Is there something like these sample?
def funcA(a,b):
return a + b
return_type(funcA)
output: <class 'Integer'>
and
def funcA(a,b):
return a + b
parameter_type(funcA)
output: [<class 'Integer'>,<class 'Integer'>]
update:
I'm trying to generate python's expression and avoiding something cannot be evaluated like this:
funcA(20, funcA(True, "text"))
In Python, a dynamically typed language, the type information of a function's parameters is required at runtime. In 3.3 and later, you can get the type of a function as follows:
from inspect import signature
def foo(a, *, b:int, **kwargs):
... pass
sig = signature(foo)
str(sig)
'(a, *, b:int, **kwargs)'
str(sig.parameters['b'])
'b:int'
sig.parameters['b'].annotation
<class 'int'>
see https://docs.python.org/3/library/inspect.html#introspecting-callables-with-the-signature-object
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With