4

I've recently started using pydev. It seems great. One annoyance though comes from the fact that python is a dynamic language. Many of the autocompletion features will work when pydev knows the type, so

  f = open("foo.txt")

works great, pydev can figure out that f is a file and gives me great suggestions.

However, when dealing with parameters in my own functions, pydev obviously can't determine type information:

  def bar(x,y): #Pydev obv. cant tell exactly what x and y are

So I obviously don't get any suggestions when I do x..

It would be great to provide some kind of annotation that pydev can pick up to add suggestions and also to help me code a little safer by warning me I should. I know I'm thinking like someone coming from a static language, but much of the time the type of an argument should always be one thing and only one thing. Can I annotate my code to help pydev out?

Doug T.
  • 64,223
  • 27
  • 138
  • 202
  • 1
    Related: [Autocompletion in dynamic language IDEs, specifically Python in PyDev](http://stackoverflow.com/q/3482622/95735), [Problem with lack of autocomplete/casting in python](http://stackoverflow.com/q/5143646/95735), [Python and Intellisense](http://stackoverflow.com/q/905005/95735), [Komodo Python auto complete: type inference by variable metadata?](http://stackoverflow.com/q/1678953/95735) – Piotr Dobrogost Jan 26 '12 at 20:27

2 Answers2

2

If x is a list, then this should work:

def bar(x,y):
   assert isinstance(x, list)
m0n0g0n
  • 21
  • 1
1

You may use:

def bar(x, y):
    """This function does something.

        @type x: str
            Describe param x
        @type y: int
            Or don't describe. But not in same line.

        @rtype int
            Function returns int
     """
     pass
Maberi
  • 11
  • 1