|
|
>>> import inspect |
>>> import inspect |
|
|
>>> inspect.getargspec(f1) |
>>> tuple(inspect.getargspec(f1)) |
(['a', 'b'], 'c', 'd', None) |
(['a', 'b'], 'c', 'd', None) |
|
|
>>> inspect.getargspec(f2) |
>>> tuple(inspect.getargspec(f2)) |
(['a', 'b'], 'c', 'd', None) |
(['a', 'b'], 'c', 'd', None) |
|
|
Note that these constructors do not copy any actual *code* from the code |
Note that these constructors do not copy any actual *code* from the code |
unpacking process, and is designed so that the ``inspect`` module will |
unpacking process, and is designed so that the ``inspect`` module will |
recognize it as an argument unpacking prologue:: |
recognize it as an argument unpacking prologue:: |
|
|
>>> inspect.getargspec(f3) |
>>> tuple(inspect.getargspec(f3)) |
(['a', ['b', 'c'], ['d', ['e', 'f']]], None, None, None) |
(['a', ['b', 'c'], ['d', ['e', 'f']]], None, None, None) |
|
|
>>> inspect.getargspec(f4) |
>>> tuple(inspect.getargspec(f4)) |
(['a', ['b', 'c'], ['d', ['e', 'f']]], None, None, None) |
(['a', ['b', 'c'], ['d', ['e', 'f']]], None, None, None) |
|
|
You can also use the ``from_spec(name='<lambda>', args=(), var=None, kw=None)`` |
You can also use the ``from_spec(name='<lambda>', args=(), var=None, kw=None)`` |
>>> c.co_argcount |
>>> c.co_argcount |
3 |
3 |
|
|
>>> inspect.getargs(c.code()) |
>>> tuple(inspect.getargs(c.code())) |
(['b', ['c', 'd'], 'e'], 'f', 'g') |
(['b', ['c', 'd'], 'e'], 'f', 'g') |
|
|
|
|
42 |
42 |
|
|
>>> import inspect |
>>> import inspect |
>>> inspect.getargspec(f) |
>>> tuple(inspect.getargspec(f)) |
(['a', 'b', 'c'], None, None, None) |
(['a', 'b', 'c'], None, None, None) |
|
|
Although Python code objects want ``co_varnames`` to be a tuple, ``Code`` |
Although Python code objects want ``co_varnames`` to be a tuple, ``Code`` |
>>> c.co_filename |
>>> c.co_filename |
'testname' |
'testname' |
|
|
>>> inspect.getargs(c.code(p)) |
>>> tuple(inspect.getargs(c.code(p))) |
(['a', 'b'], 'c', 'd') |
(['a', 'b'], 'c', 'd') |
|
|
Notice that you must pass the parent code object to the child's ``.code()`` |
Notice that you must pass the parent code object to the child's ``.code()`` |
>>> f |
>>> f |
<function f at ...> |
<function f at ...> |
|
|
>>> inspect.getargspec(f) |
>>> tuple(inspect.getargspec(f)) |
(['a'], None, None, (42,)) |
(['a'], None, None, (42,)) |
|
|
>>> f() |
>>> f() |
>>> f |
>>> f |
<function f at ...> |
<function f at ...> |
|
|
>>> inspect.getargspec(f) |
>>> tuple(inspect.getargspec(f)) |
(['a', 'b'], 'c', 'd', (99, 66)) |
(['a', 'b'], 'c', 'd', (99, 66)) |
|
|
>>> dis(f) |
>>> dis(f) |
>>> from peak.util.assembler import LOAD_CONST, POP_BLOCK |
>>> from peak.util.assembler import LOAD_CONST, POP_BLOCK |
|
|
>>> import sys |
>>> import sys |
>>> WHY_CONTINUE = {'2.3':5, '2.4':32, '2.5':32}[sys.version[:3]] |
>>> WHY_CONTINUE = {'2.3':5}.get(sys.version[:3], 32) |
|
|
>>> def Switch(expr, cases, default=Pass, code=None): |
>>> def Switch(expr, cases, default=Pass, code=None): |
... if code is None: |
... if code is None: |