fix(typing): Improve Then annotations, autocompletion, docs#3567
Merged
dangotbanned merged 35 commits intovega:mainfrom Sep 22, 2024
Merged
fix(typing): Improve Then annotations, autocompletion, docs#3567dangotbanned merged 35 commits intovega:mainfrom
Then annotations, autocompletion, docs#3567dangotbanned merged 35 commits intovega:mainfrom
Conversation
Purely demonstrating type checking behaviour for vega#3552 (comment)
Revisting these I found it confusing that they were defined like (A, B, B, A). They are now (A, A, B, B) so it is clearer how they are linked
Aiming to get all of these to pass, without breaking anything else. **CI fail expected**
SchemaLikeThen annotations, simplify autocompletion
…-compliant
Can't define this in `OperatorMixin`, as `Expression` uses `{"type": "string"}`
Added a lot of notes here, since I was surpised `Then` would not be allowed in the cases I had planned originally
We're using a feature that didn't make it into `3.13` yet https://peps.python.org/pep-0728/
The warning raised by `pyright` here was actually quite helpful. Essentially, a shorthand string is never allowed here vega#3552 (comment)
We now provide more precise errors identifying exactly which call produced the issue.
Previously, the `.then("min(foo):Q")` was silently allowed - but later rejected in `.otherwise()`.
I'm fairly sure this is fixed in another branch, so leaving this here for less of a conflict https://github.com/vega/altair/pull/3547/files#diff-bbe4e187b18d242a366c820d023afd89041759cb96e4ec66c3f34559a72c2f9d
No longer inherited
dangotbanned
commented
Sep 15, 2024
dangotbanned
commented
Sep 15, 2024
dangotbanned
commented
Sep 15, 2024
dangotbanned
commented
Sep 15, 2024
dangotbanned
commented
Sep 15, 2024
Removes the need for hardcoding restrictions in multiple places
…edDict`) - Adds some more consistency between `condition` and `when-then-otherwise` - 1 less thing to think about
This isn't a runtime concern, just to satisfy typing
Mostly pushing this as an experiment. Shortens signatures, but there is a cost to the indirection vega#3567 (comment)
Then annotations, simplify autocompletionThen annotations, autocompletion, docs
dangotbanned
commented
Sep 17, 2024
Member
Author
Thanks for the review @binste |
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.
Fixes #3552
Overview of issues by @binste in comment
The draft PR is very helpful! Trying to summarise/reword it for myself:
Thenshould not inherit fromSchemaBaseas it muddies autocompletionSchemaBasepass due toalt.conditionandalt.when().then().otherwise(). Can beSchemaBaseor a protocolSchemaLike. If I understand it correctly, we mainly introduce it now to make these types work.How about
Conditionis not yet used anywhere in the codebase and it makes it clearer what we intend to do with the protocol. What do you think?Tasks
TheninChart.encode(), without subclassingSchemaBaseChart.encode()annotations08bf16e(#3567)(Condition|Schema)Liked20109e(#3567)TypeAlias|TypedDictinapi.py0a6d599(#3567)0a93309(#3567)Related
0bdfa72(#3536)Note
This PR started as a draft proposal for addressing multiple related issues.
See #3552 (comment) for further info
Draft PR Demo
Purely demonstrating type checking behavior for #3552 (comment)
Extended chart_encode
Note
mypyfailing is expected and part of the demonstration