homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Flag inappropriate uses of callable class attributes
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.3
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, Trundle, alex, daniel.urban, eckhardt, eric.araujo, eric.snow, gvanrossum, ncoghlan, twouters
Priority: normal Keywords: patch

Created on 2011年03月11日 19:22 by twouters, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
nonmethod-warn.diff twouters, 2011年03月17日 17:30 review
Messages (6)
msg130606 - (view) Author: Thomas Wouters (twouters) * (Python committer) Date: 2011年03月11日 19:22
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.
msg130610 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011年03月11日 20:24
Don’t forget to remove the comments in codecs that are made obsolete by your changes.
msg130617 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2011年03月11日 21:41
This should not reuse DeprecationWarning but instead introduce a different warning, e.g. CompatibilityWarning.
msg131270 - (view) Author: Thomas Wouters (twouters) * (Python committer) Date: 2011年03月17日 17:30
New version of the patch; instead of triggering at attribute *access*, this just checks when creating types and in type_setattro. It also makes the warning a newly added CompatibilityWarning. Also, instead of warning for all non-descriptors, it now only warns for PyCFunctionObjects that do not have a __self__ set, or of which __self__ is a module. (The reason for the latter being the new-ish behaviour of functions defined in modules in C getting passed something as __self__, defaulting to the module.) I've removed a few staticmethod calls from cases that do not trigger the new warning.
This patch still lacks tests and doc updates, but I'm uploading right now because the sprints apparently lose internet soonish.
msg140265 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011年07月13日 15:14
Hi Thomas, could you give us a status update? Maybe I can help with tests or docs?
msg222712 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014年07月10日 23:25
This issue is referred to from #11455.
History
Date User Action Args
2022年04月11日 14:57:14adminsetgithub: 55679
2017年05月22日 19:27:35twouterssetstatus: open -> closed
resolution: out of date
stage: resolved
2014年07月10日 23:25:07BreamoreBoysetnosy: + BreamoreBoy
messages: + msg222712
2013年06月05日 04:33:38ncoghlansetnosy: + ncoghlan
2013年02月25日 16:23:49eckhardtsetnosy: + eckhardt
2011年07月13日 16:14:12eric.snowsetnosy: + eric.snow
2011年07月13日 15:14:48eric.araujosetmessages: + msg140265
2011年03月17日 17:31:02twouterssetfiles: - nonmethod-warn-nongit.diff
nosy: gvanrossum, twouters, eric.araujo, alex, Trundle, daniel.urban
2011年03月17日 17:30:43twouterssetfiles: + nonmethod-warn.diff
nosy: gvanrossum, twouters, eric.araujo, alex, Trundle, daniel.urban
messages: + msg131270
2011年03月11日 21:41:12gvanrossumsetnosy: + gvanrossum
messages: + msg130617
2011年03月11日 20:26:27twouterssetfiles: - nonmethod-warn-nongit.diff
nosy: twouters, eric.araujo, alex, Trundle, daniel.urban
2011年03月11日 20:26:18twouterssetfiles: + nonmethod-warn-nongit.diff
nosy: twouters, eric.araujo, alex, Trundle, daniel.urban
2011年03月11日 20:24:02eric.araujosetnosy: + eric.araujo
messages: + msg130610
2011年03月11日 20:22:13twouterssetfiles: - nonmethod-warn.diff
nosy: twouters, alex, Trundle, daniel.urban
2011年03月11日 20:21:58twouterssetfiles: + nonmethod-warn-nongit.diff
nosy: twouters, alex, Trundle, daniel.urban
2011年03月11日 19:57:36daniel.urbansetnosy: + daniel.urban
2011年03月11日 19:25:49alexsetnosy: + alex
2011年03月11日 19:23:25Trundlesetnosy: + Trundle
2011年03月11日 19:22:07twouterscreate

AltStyle によって変換されたページ (->オリジナル) /