Attempt to statically collect types in typeshed (ahead of time)#56
Draft
Attempt to statically collect types in typeshed (ahead of time)#56
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A first shot at #42.
This is an attempt to build a map of all usable type imports in Python's
_typeshed. That would make docstub a lot more able to match doctypes to a valid Python type.I initially thought, I had gotten pretty far by re-purposing the
TypeCollectorclass. Unfortunately,_typeshedmakes heavy use of re-importing types. E.g. the content ofcollections.abc:This means the current approach in
tools/collect_stdlib_types.pywill miss a lot of types.This means resolving references and semantic analysis which is a lot more tricky to do. I think it's possible but would take a lot of work that's not actually the focus of docstub. It would also re-implement the wheel since mypy, basedpyright, etc. must have already figured that out.
So from that point, I looked into mypy's internals (including stubtest & stubgen), aiming to leverage mypy to create the list of types in
src/docstub/_stdlib_types.py. To be honest, I couldn't make a lot of sense of it, even armed with a debugger. 🙈Besides asking for support on the appropriate mypy channel, I don't have a lot of concrete ideas on proceeding right now. I could explore using a proper language server. But that seems similarly complicated right now.
I could use intersphinx mappings like suggested in #22. But I'm not sure if that actually contains all types. It's an interesting approach. Not all third-party packages may provide an intersphinx mapping but there might be packages that do but don't have stubs available. And it's already pretty close to what I actually want as output...