Movatterモバイル変換


[0]ホーム

URL:


[Python-Dev] Arbitrary attributes on funcs and methods

Paul Prescodpaul@prescod.net
Wed, 12 Apr 2000 07:20:18 -0500


Vladimir Marangozov wrote:>> ...>> I don't see the purpose of attaching state (vars) to an algorithm> (i.e. a function).A function is also an object.> What are the benefits compared to class instances?If I follow you, you are saying that whenever you need to associateinformation with a function, you should wrap up the function and objectinto a class. But the end result of this transformation could be aprogram in which every single function is a class. That would beincredibly annoying, especially with Python's scoping rules. In general,it may not even be possible.Consider the following cases:  * I need to associate a Java-style type declaration with a method sothat it can be recognized based on its type during Java method dispatch.How would you do that with instances? * I need to associate a "grammar rule" with a Python method so that themethod is invoked when the parser recognizes a syntactic construct inthe input data. * I need to associate an IDL declaration with a method so that a COMinterface definition can be generated from the source file. * I need to associate an XPath "pattern string" with a Python method sothat the method can be invoked when a tree walker discovers a particularpattern in an XML DOM. * I need to associate multiple forms of documentation with a method.They are optimized for different IDEs, environments or languages.> And these special assignment rules because of the real overlap with> real instances... Grrr, all this is pretty dark, conceptually.I don't understand what you are saying here.> Once the puzzle would be solved, we'll discover that there would be only> one additional little step towards inheritance for modules. How weird!> Sounds like we're going to metaclass again...I don't see what any of this has to do with Barry's extremely simpleidea. Functions *are objects* in Python. It's too late to change that.Objects can have properties. Barry is just allowing arbitrary propertiesto be associated with functions. I don't see where there is anythingmysterious here.--  Paul Prescod  - ISOGEN Consulting Engineer speaking for himself"I and my companions suffer from a disease of the heart that can onlybe cured with gold", Hernan Cortes


[8]ページ先頭

©2009-2025 Movatter.jp