Reputation: 543
Is it possible to declare python functions with specific class parameters? The reason is that I want to avoid type errors (Happens to me quiet often)
For example:
def connect(socket as socket, HOST, PORT):
return socket.connect((HOST, PORT))
The goal here would be that if I type 'socket.' the autocompletion would show me any functions available on the socket class. Since I am passing it as an argument the autocompletion which pops up is empty. The reason is that you can pass every object to the function.
Upvotes: 1
Views: 1745
Reputation: 11681
Python has syntactic support for type annotations, but Python itself doesn't have autocomplete. That's provided by third-party tools, like PyCharm and Jedi. Some of these applications (like PyCharm) can use static inference to get better completions if you annotate your functions properly.
Say you start typing in a function into PyCharm like this,
def foo(a_dict: dict) -> int:
print(a_dict.i▏
Then it will be able to infer that a_dict
is a dict and pop up a completion window with dict methods, like items()
.
Upvotes: 3