When using pydev, can you annotate parameters with a type name to give me contextual information?

I recently started using pydev. It seems healthy. One annoyance is that python is a dynamic language. Many autocomplete functions will work when pydev knows the type, so

f = open("foo.txt") 

works fine, pydev can understand that f is a file and gives me great suggestions.

However, when dealing with parameters in my own functions, pydev obviously cannot determine the 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 as well as help me protect a bit better by warning me what I should. I know that I think someone is from a static language, but in most cases the type of argument should always be one and only one. Can I comment on my code to help pydev?

+4
source share
2 answers

If x is a list, then this should work:

 def bar(x,y): assert isinstance(x, list) 
+2
source

You can 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 
+1
source

Source: https://habr.com/ru/post/1393215/


All Articles