Inspector Gadget - Extended Python Inspection
Links
API
Inspector Gadget - Extended Python Inspection.
This module extends the python built-in inspect
module
get_signature
- Get Signature as a stringgetsize
- Sum Size of obj and Members
- inspectorgadget.get_signature(func, vars_=None, exclude=None)[source]
Return signature of func as string.
>>> def func(a, b=2): ... return a + b >>> get_signature(func) 'func(a, b=2)'
In case of given variables vars_ the caller equivalent is returned.
>>> get_signature(func, {'a': 4, 'b': 2}) 'func(4)' >>> get_signature(func, {'a': 4, 'b': 9}) 'func(4, b=9)'
This is useful in combination with vars().
>>> def func(a, b=2): ... print(get_signature(func, vars())) >>> func(10, b=8) func(10, b=8)
Positional arguments:
>>> def func(a, *b): ... print(get_signature(func, vars())) >>> func("a", "b0", "b1") func('a', 'b0', 'b1')
Keyword arguments (Please note, that the kwargs are sorted by name):
>>> def func(a, **kwargs): ... print(get_signature(func, vars())) >>> func("a", foo=4, bar=8) func('a', bar=8, foo=4)
Parameters can be hidden via exclude by name or index.
>>> def func(a, b, c, d=None, e=None): ... print(get_signature(func, vars(), exclude=(0, "d", "g"))) >>> func('a', 'b1', 'c2', 'd3', 'e4') func('b1', 'c2', e='e4')
- inspectorgadget.getsize(obj, blacklist=(<class 'type'>, <class 'module'>, <class 'function'>))[source]
Sum Size of obj and Members.
>>> import sys >>> sys.getsizeof('a') 50 >>> sys.getsizeof('b') 50 >>> sys.getsizeof(('a', 'b')) 56 >>> getsize(('a', 'b')) 156 >>> def myfunc(a): ... return a >>> getsize(myfunc) Traceback (most recent call last): ... TypeError: getsize() does not take argument of type: <class 'function'>