fix(typing): Revise generated annotation order #3655
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.
Description
The doc stated that
None
would appear after builtins.altair/tools/schemapi/utils.py
Lines 855 to 864 in 2ba89d5
However, this assertion doesn't hold for any
builtin
with a name length greater than 4.The issue is not new, but became more apparent to me while writing #3653 (comment)
Example
Below
float
appears afterNone
Before
altair/altair/vegalite/v5/schema/_config.py
Line 5004 in 2ba89d5
After
altair/altair/vegalite/v5/schema/_config.py
Line 5004 in e656661
Note
I was unable to work out a sorting strategy to achieve what the doc had intended.
Instead, I've opted to always place
None
last in the context it appears.This is much easier to do, and is generally what most people would write (and expect to see).
In the non-generated code, this is already the pattern we use:
altair/altair/vegalite/v5/api.py
Line 2091 in 2ba89d5
altair/altair/vegalite/v5/api.py
Line 3494 in 2ba89d5
altair/altair/vegalite/v5/api.py
Line 3859 in 2ba89d5
Preventing regressions
I've started small, but have included a few doctests (f9f0a53) that are now run alongside (20d5c17) those in
altair
,tests
.