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

Using type hint Any in Django – NameError: name 'Any' is not defined

When I use the autocomplete suggestion in VSCode to make a get_context_data() function:

    def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
        return super().get_context_data(**kwargs)

I get a NameError:
NameError: name 'Any' is not defined

I am new to using type hints in Python – do I need to import something for type Any?

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

>Solution :

Any in this context is a type annotation. You need to import it from the typing module for it to be recognized.

from typing import Any

Should solve your problem.

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