Reputation: 33
I recognize from c# that you could do
(int)(randomVariable + 1 + anythingElse)
and the IDE would understand that the named variable/result is an integer.
Now in Python I want to let my IDE know, that in the list ceDocs which I am sending as a parameter will be objects of the class Doc so I can use autocomplete and proper coloring instead of "any" everywhere.
def createDocuments(ceDocs):
for doc in ceDocs:
doc.name = doc.path # example action
createDocuments(getFromPath(path))
Is there a way to do this in python?
Please correct me if this makes no sense... :)
Upvotes: 1
Views: 66
Reputation: 11952
For python 3.10:
def createDocuments(ceDocs: list[Doc]):
for doc in ceDocs:
doc.name = doc.path # example action
For earlier versions:
from typing import List
def createDocuments(ceDocs: List[Doc]):
for doc in ceDocs:
doc.name = doc.path # example action
Upvotes: 1
Reputation: 1557
Use type hints with the typing
module.
from typing import List
class Doc:
# ...
def createDocuments(ceDocs: List[Doc]):
for doc in ceDocs:
doc.name = doc.path # example action
Upvotes: 2