[issue17499] inspect.Signature and inspect.Parameter objects are mutable

Larry Hastings report at bugs.python.org
Wed Mar 20 22:09:19 CET 2013


New submission from Larry Hastings:

The documentation for Inspect.Signature and Inspect.Parameter states that the objects are immutable.  And they go to great lengths to provide a convenient interface allowing you to "replace" members.

However, the objects make only a pathetic effort at being immutable.  They hide their public API members (e.g. "name") behind a property, which they store internally in a member prefixed with an underscore (e.g. "_name").  BUT THE INTERNAL MEMBER IS EXTERNALLY MUTABLE.

Example code:

    >>> def foo(i=3): pass
    >>> sig = inspect.signature(foo)
    >>> str(sig)
    '(i=3)'
    >>> sig.parameters['i']._name ='silly'
    >>> str(sig)
    '(silly3)'

----------
components: Library (Lib)
messages: 184796
nosy: brett.cannon, larry
priority: low
severity: normal
stage: test needed
status: open
title: inspect.Signature and inspect.Parameter objects are mutable
type: behavior
versions: Python 3.3, Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17499>
_______________________________________


More information about the Python-bugs-list mailing list