I am writing a new library from scratch in Python, I would like to use Mypy for type checking. But I don't know if it's better to specify the types in the source code or in a stub file .
I see that projects like Django have a different repository with stubs (this project would merge with the original project when it's done), while others like Pandas have the types in the .
What would be better for maintainability? Why aren't contributors doing PR with types inside the Django code instead of a fork with stubs? Is there any good practice on this? I have read PEP 484 but it doesn't mention a preferred method or use cases.
From already thank you very much!
After some time I have consulted different sites informally and they have told me that the Stubs files are to add support to large projects that are already written and that changing the code to add typing can be an expensive process or even go against the plans of the developers who maintain a project, as is the case with Django where the team considers that it would add more problems than solutions ( proposal on Github ). In this way you can create a file with the typed structure that can be incorporated into a project already installed independently.
In the event that a library is made from scratch with support for Mypy types, typing can be added to the core without any problems, since it absolutely affects the final performance of the Python code.
Obviously there is no global solution, but you must choose the option that best suits the needs of each project.