Review Request: Add possibility to store Decorators for class- and function declarations

Sven Brauch svenbrauch at gmx.de
Sat Aug 27 07:08:00 UTC 2011



> On Aug. 27, 2011, 12:19 a.m., Milian Wolff wrote:
> > I have no clue about python: what is a decorator? the @staticmethod ? Then the def foo function definition should be marked static. What is the decorator trying to solve?

Hey,

in python, you don't write "static int foo", but "def foo", and then foo = staticmethod(foo). The "staticmethod" function converts the "foo" function into a new one which is static. To simplify this, instead of

class my_class():
  def foo(): pass
  foo = staticmethod(foo)

you can also write

class my_class():
  @staticmethod
  def foo(): pass

Those two are equivalent. You can also define your own decorators, which take functions as arguments and return other functions. There's also a few predefined ones in python.

Doesn't PHP also have that "@" syntax? Or is that just in docstrings?

Whatever, kdev-python documentation files do something like this:

@TypeContainer
class list():
    @appendsType(0)
    def append(arg0): pass

This is the way to let my code know it should track the content type of "list" instances, and other decorators tell it which functions modify that content type.


- Sven


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://git.reviewboard.kde.org/r/102432/#review6041
-----------------------------------------------------------


On Aug. 25, 2011, 1:22 p.m., Sven Brauch wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> http://git.reviewboard.kde.org/r/102432/
> -----------------------------------------------------------
> 
> (Updated Aug. 25, 2011, 1:22 p.m.)
> 
> 
> Review request for KDevelop.
> 
> 
> Summary
> -------
> 
> This adds a list of Decorators to each class and function declaration, and a Decorator class which stores information about those decorators.
> This is currently relevant for the python language, which has a pattern like this:
> 
> class c():
>     @staticmethod
>     def foo():
>         pass
> 
> I didn't have an internet connection for research available, but I think other languages might have similar patterns, so this can go into kdevplatform.
> Also, even after several hours of experimentation I couldn't figure out how to inherit from a class which defines appended lists, adding another one... some documentation on that would be appreciated :)
> 
> 
> Diffs
> -----
> 
>   language/CMakeLists.txt 4399ebb 
>   language/duchain/classdeclaration.h 409a3a4 
>   language/duchain/classdeclaration.cpp 0670209 
>   language/duchain/decorator.h PRE-CREATION 
>   language/duchain/functiondeclaration.h 7f084a9 
>   language/duchain/functiondeclaration.cpp fb442dc 
> 
> Diff: http://git.reviewboard.kde.org/r/102432/diff
> 
> 
> Testing
> -------
> 
> 
> Thanks,
> 
> Sven
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20110827/ace29498/attachment.html>


More information about the KDevelop-devel mailing list