fellow humans.
First off, this is my first question here so I apologize if I'm not following the proper etiquette.
I am a 3rd year CS student and fairly new to programming in python with most of my experience coming from C/C++/Java. Something I relied on was the list of methods that is populated when I start typing a functions parameter in dot notation. I am assuming that this is because the parameter's type is defined in the function declaration.
In python, since any object can be passed to any function, how do I get access to this same populated list of the parameter's class methods when writing a function? I always found this extremely useful when a class may be multiple layers of inheritance deep.
Just for reference, I would obviously only want the Python function to be able to accept a specific class or interface. I also had a great deal of difficulty finding an answer on google so I'm sorry if I'm missing some glaring detail.
Thanks in advance for any answers!
I would obviously only want the Python function to be able to accept a specific class or interface
Python has support for gradual typing: you can choose to put type annotations on your functions (see PEP 3107 and PEP 484)
def add(x: int, y: int) -> int:
return x + y
Python on its own doesn't care about these annotations, and won't stop you from calling add
with a string and a socket. However, there are external tools called "type checkers", such as mypy and pyright that understand these annotations.
These type annotations also help IDEs with autocompletion, which seems to be your main concern. Here's a screenshot from PyCharm: