-
Notifications
You must be signed in to change notification settings - Fork 20
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
pytypes code is not completely annotated #74
Comments
Adding annotations in pytypes proved disastrous for certain modes, e.g. within a typecheck profiler. It would try to check itself while checking something, ending in an endless typecheck loop. Sure, there are better fixes, e.g. adding |
Yes, |
Normally type annotations for a library are important for public API, as they help to make sure that the code that uses that API is doing it correctly. Annotating everything that's not part of public API would only help to verify the correctness of the library itself, and that can be provided by other means and thus is less important. |
I ran into pretty annoying issues where I ironically lost static type information whenever I tried to enable runtime type checking with the |
Would it help for now, i.e. to solve the issue with loosing static type info, to just annotate the decorators according to python/mypy#3157? Also note that you can apply pytypes' decorators to the whole module which would likely prevent them from being visible as decorators to mypy (did not test this). |
Yeah, I think that matches what I had in mind. These would just be changes to add annotations in typechecker.py? |
Yes, at pytypes/pytypes/typechecker.py Line 1007 in da05635
I further hope that it won't cause issues that typechecked also accepts classes. I think we don't need tests for this because such tests would involve a static type checker I suppose. It wood be good to have some instructions or example to test it before a release. E.g. in the docstring of typechecked. |
Okay, I figured out the gist of the changes, but pytype found several type issues in the same file, and I'm having trouble understanding from PEP 561 if adding a Some of these look like legit bugs or easy improvements...
Please let me know if it's safe to just go ahead and add the |
Thanks for spotting this. Regarding the possibly uninitialized |
See d5c08b0 |
Yeah, uninitialized None errors are easily resolved with Adding assertions to help the checker (and human readers) follow the invariants is common, not magical at all. The checker is not a serious theorem prover so there are plenty of cases that are guaranteed for reasons it doesn't understand. There's even one it misses right above the |
Perfect. Then please feel free to add asserts as required. |
I was also wondering if we could change the module name case for |
I think the module case does return the module only to be consistent with its behavior in decorator case, where it always returns the input member. You find it best for type annotation to return always None in module case? I am also fine with that if it breaks no test, but as said above I suspect it would complicate annotation of the generic |
Nah, I wasn't attached to the None idea. Actually I agree making it string→string / module→module unconditionally is intuitive and way simpler for the typing. Seems like you're on board with the idea, so I went ahead and filed #97 for any further discussion and I can send a PR for that shortly. |
This was closed automatically due to 95d58a3. However, that commit only adds annotations for |
You could reword the issue to "not completely annotated" for clarity if it's going to stay open long. The only problem for me was pytypes losing type information in projects that use it. I can't think of any big advantages to proactively adding type hints on the rest. Eventually it might help for some IDE features / autocomplete, but for now most tooling like python-language-server doesn't even notice types outside of typeshed. |
I think there's nothing wrong with adding remaining type info (in long term). Last but not least because it serves documentation purposes. |
The source code of
pytypes
itself contains no annotations and no stubs are present either.Therefore
mypy
issues warnings while checkingpytypes
-enabled code.The text was updated successfully, but these errors were encountered: