Try improving CC type hinting #3023
Merged
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.
Effectively just uses a bit of
Anyto get a best effort result.What we'd like to do is to infer the type of
CC.job_queuefrom theApplication. However, this is problematic, as the app has a type for the used (sub)class ofCallbackContextitself. in particular, when speciyinf a subclass withContextTypes, we'd like to somehow sayCallbackContext[ExtBot, dict, dict, dict, TypeVar('JQ')]+App[…, JobQueue]=CC[…, JobQueue]. Similar things happen onCC.__init__/from_*.I don't see how this can be achieved with the current status of the
typingmodule, as neithernor something like
are currently supported.
Hence,
CallbackContext.job_queuestays annotated asOptional[JobQueue].@harshil21 if you can test if pyright works with this as well, that would be nice. We can then maybe merge into #3017 and then merge both together into master.
Example snippet of what I've tested with mypy: