Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to show the IDE which Type of Objects are in a List, so it colors / autocompletes properly?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 getFromPath(path):
    fileNames = glob.glob(path + "*")
    files = []
    for file in fileNames:
        files.append = Doc(file)
    return files

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… 🙂

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading