[New-bugs-announce] [issue11470] Flag inappropriate uses of callable class attributes

Thomas Wouters report at bugs.python.org
Fri Mar 11 20:22:09 CET 2011


New submission from Thomas Wouters <thomas at python.org>:

As discussed at the language summit at PyCon 2011, some code takes some liberties with setting class attributes to callable objects, like CFunctions, that (C)Python does not turn into methods. This is problematic because 1) CPython can't then turn that CFunction into a regular function, and 2) other implementations have to specialcase the builtins to emulate the behaviour.

This patch adds a warning when a non-descriptor, non-class callable attribute is accessed in a context that would have fired the descriptor. It also fixes a bunch of these warnings that show up when running the testsuite. Some of these warnings are obviously (to me) incorrect code  -- like the io testsuite, which uses staticmethod around pyio.open but not io.open, or the encoding classes that use an encode function from an extension module as a class attribute. Some of the warnings are debatable, but have an obvious fix (wrap in staticmethod.) Some could be considered false-positives because they actually use (what amounts to) a a bound instance method as a class attribute (for example, re.compile('...').match.)

The patch is still a work in progress, I'm just uploading to start the discussion sooner rather than later.

----------
components: Interpreter Core
files: nonmethod-warn.diff
keywords: patch
messages: 130606
nosy: twouters
priority: normal
severity: normal
status: open
title: Flag inappropriate uses of callable class attributes
type: feature request
versions: Python 3.3
Added file: http://bugs.python.org/file21085/nonmethod-warn.diff

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


More information about the New-bugs-announce mailing list