Bug or feature?

Tim Peters tim.one at home.com
Sat Sep 1 21:25:31 CEST 2001

[Gerson Kurz]
> Consider:
> class a:
>     def b(self,x):
>         print "call #1"
>     def b(self,x):
>         print "call #2"
> v = a()
> v.b(42)
> This code raises no warning, and can be executed ('call #2' will be
> printed), on Python 2.1.1 (ActivePython Build 212). Bug or feature?

Neither, really -- it's just the way it works.  A def in Python is an
executable stmt, and, when executed, binds the name following the "def" to
the appropriate code object, in the appropriate namespace.  So at heart it's
no more a bug or feature than that, e.g.,

    v = 1
    v = 2
    print v

prints 2 without warning.  Assignments and defs are both binding stmts.

The latest version of PyChecker, at


produces this for your snippet, where I put it in file testchk.py, with the
class stmt on the first line:


testchk.py:5: Parameter (x) not used
testchk.py:5: Redefining attribute (b) original line (2)

So the real question is why you didn't consider an unused argument to be
just as suspicious <wink>.

telepathic-programs-are-fun-ly y'rs  - tim

More information about the Python-list mailing list