-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expand type hints across projects #98
Comments
I'm happy to accept contributions! I tried to find a popularity ranking of all Python packages, but I didn't succeed. I did find snyk Advisor provides a quick and easy way to find packages by first letter (https://snyk.io/advisor/packages/python/j). You could go through the list of packages there and look at the popularity of each. It also sounds as if the pypi downloads tables are available to be queried (https://pypistats.org/api/#etiquette), so you could probably construct a query to do that. You might also search Github for projects with the skeleton badge - that's a pretty good indicator that it's following my best practices. Tips
|
I am used to type checking my code with mypy in strict mode. While some may see the strict mode as too aggressive, I will have no problem adjusting a bigger codebase to pass strict type checking. This is what I had in mind during writing the message.
mypy disallows untyped definitions in the strict mode. A private function without the class Foo:
def _bar(self): # seen by mypy as untyped
pass
reveal_type(Foo()._bar()) # Revealed type is "Any"
class Spam:
def _eggs(self, biz: int): # seen as typed, return assumed to be Any
pass
reveal_type(Spam()._eggs(5)) # Revealed type is "Any" Note The only exceptions from the behavior above are Relevant resources: While no presence of the class Example:
def _com(self, port: int):
return None
reveal_type(Example()._com(43)) # Revealed type is "Any" In places where the value of such a method is being used, the type hinting noise is then simply necessary to inform mypy about the actual return type that affects other scopes of the codebase. I firmly believe that the best option would be being as explicit as possible when annotating types, because, as it seems, there are too few obvious cases at the end of the day. The Zen of Python, by Tim Peters:
Note: The examples were tested on mypy 1.7.0. |
Thank you for your time spent on the research. I will use these resources and compile a TO-DO list of the projects to work on in this issue. Every subsequent PR will reference this issue. |
Of course if the new type hints would appear too intricate for the eye, which I can totally understand, there is always an option of creating stubs to isolate two worlds of the implementation and the type hints, like in jaraco/jaraco.functools#22. What are your thoughts on this @jaraco? |
An interesting approach would be to measure—for every project—how many PyPI projects depend on it, using libraries.io. But I think it would more or less correlate with downloads/month anyway, as I am assuming (without having done any research) that most of these downloads come from pipelines that install every dependency for the first time, and dependencies referencing the same project being together aren't that common (so like, when for two projects A and B sharing the same project X as a dependency, X in fact gets installed "twice less", because only once, as it is reused in the same environment by A and B, even though I would technically call X more popular in this case). This can get even more interesting if we add distinction between pip-like and pipx-like installation methods, where a shared dependency would be installed twice for separate environments of A and B, assuming A and B are CLI applications... I could be pointing out all the things that come to my mind further, and it gets very complicated and multilayered as I dig in the rabbit hole. Yeah, so all in all I've learned that "package popularity" isn't trivial, because both the convergence in the web of dependencies as well as the statistics of total downloads in time play a role in the correct evaluation of how popular a package really is. Anyway though, this is just an attempt to prioritize the tasks. Since some most popular jaraco projects commonly depend on some less popular jaraco projects (downloads/month-wise!), I started off from jaraco.functools and jaraco.classes. |
Amazing analysis. Thanks! You'll notice that libraries.io is a project by Tidelift. You may have noticed that I also work with them as they work to garner support for open source maintainers from the enterprise users. They've probably built other tooling and may even be interested in collaborating on tooling to support open source maintenance. You may want to consider signing up with them as a maintainer (there's no cost and could potentially pay) and engaging on the forums to see if there is interest in collaborating. If you need a referral or anything to get signed up, let me know. |
Thank you! I've just applied to lift a few of my projects! Due to a considerable number of projects that need similar work, I created a project that aims to automate the whole process as much as possible—autorefine. MonkeyType will turn out very handy when it comes to type hints generation. I will take care of making them as sophisticated as needed. I think all these projects have enough coverage, so I will simply generate the types by running tests. I will leverage LibCST and create custom rules if needed for modernizing the projects (some had their last releases a few years ago)—but this is out of scope at the moment. Contributions & suggestions very, very welcome—I am learning. Hopefully the tool will speed up |
I've made a Coherent OSS project for the initiative: https://github.com/orgs/coherent-oss/projects/3/views/2 |
I guess that's fine. I should probably get used to Python being more verbose and less essential. |
Well, I guess it's just that Python wasn't built for being statically typed. 🤷♀️ |
As more skeleton-based projects get typed (with a |
I received this inquiry in discord:
The text was updated successfully, but these errors were encountered: