Closed MartinThoma closed 4 years ago
I do not really have strong feelings about Python 2. I supported it in the past, but now I have no problem dropping it, and in fact I have dropped it on many of my other projects.
But I do feel a bit reluctant to add type hints directly into the source code. I don't think such a simple extension, which relies only on primitive types, will benefit much from them. And type hints have a way of making simple code look harder to parse visually (personal opinion, of course).
The ideal solution for me would be to have a stub file hosted externally and maintained by someone who benefits from this.
The ideal solution for me would be to have a stub file hosted externally and maintained by someone who benefits from this.
I can understand your reason not to add the type annotations within the source code. Why would you prefer not to include stub files in the repository?
The big advantage to me of having type annotations or stub files directly within the project is that every user will automatically benefit from it. I've asked this question because I had a look at where a project's type coverage is not so great and Flask-HTTPAuth popped up. I hoped that somebody might have created type annotations for it already (and I'm still hoping :crossed_fingers: )
Why would you prefer not to include stub files in the repository?
I do not have interest in maintaining the stub file.
Ah, ok, I understand that. I guess then we can close this here.
Can people still comment here as a central point for this topic? I would like to try to write a mypy plugin, similar to sqlalchemy-stubs, but I haven't created a mypy plugin so far. I will need a bit of time .
Can people still comment here as a central point for this topic?
Of course.
I will develop this here: flask-httpauth-stubs
. I've just added a stub generated by MonkeyType
. I still need to figure out how to tell mypy to use it.
Unrelated side note: Thank you so much for writing your Mega-Tutorial! This is how I got into web development with Python :-) I love the tutorial - it's awesome! :heart:
@MartinThoma That's awesome. Once you have this let me know and I'll reference it in the docs for those who are interested.
@miguelgrinberg It seems to work now :tada: https://pypi.org/project/Flask-HTTPAuth-stubs/
@MartinThoma you left some actual Python code in the HTTPDigestAuth class.
Also, how will people know which version of your stubs goes with a given version of the package? It seems people interested in types don't care about that level of accuracy?
you left some actual Python code in the HTTPDigestAuth class.
Yes. I wasn't sure how to tell mypy that the class has attributes, so I left the constructors as they are.
Also, how will people know which version of your stubs goes with a given version of the package?
I've added Flask-HTTPAuth as a dependency and set a minimum version: https://github.com/MartinThoma/flask-httpauth-stubs/blob/main/setup.py#L37
I wasn't sure about best pracitices there. Maybe rather Flask-HTTPAuth==4.*
?
I missed the minimum version, I guess that's better.
I honestly don't know how this is supposed to work. The typeshed project does not appear to be trying to match versions either (or maybe I'm not familiar enough with it to understand how they do it).
Are there plans to add type annotations or stub files for mypy to flask-httpauth?
As you seem to want to support Python 2, I guess stub files would be the way to go. Would you be open to a PR?