feat(typing): @deprecated versioning, IDE highlighting#3455
feat(typing): @deprecated versioning, IDE highlighting#3455
@deprecated versioning, IDE highlighting#3455Conversation
Supporting draft PR to attach to upcoming issue
This wrapper format seems to satisfy `pyright` enough to trigger a strikethrough
@deprecated improvements
- The export is safe and doesn't leak to top level
Non-decorator counterpart to `@deprecated`
@deprecated improvements@deprecated improvements
@deprecated improvements@deprecated versioning, IDE highlighting
binste
left a comment
There was a problem hiding this comment.
Nice one! :) Thanks for another great PR.
I only added 1 question. Also, I can't replicate that VS Code strikes through the deprecated functions:
I'm getting the deprecation warnings at runtime which is good but is there any way how I can check if pyright correctly identifies the deprecated function as being a wrapper around te.deprecated? And does mypy support this as well?
Thanks @binste
In the top-level folder I've got a workspace (locally) with these settings: {
"settings": {
"python.analysis.diagnosticSeverityOverrides": {
//"reportDeprecated": "warning",
"reportInvalidTypeForm": "none",
"reportMissingImports": "none",
"reportMissingModuleSource": "none"
//"reportUndefinedVariable": "none"
},
"python.analysis.inlayHints.functionReturnTypes": true,
"python.analysis.supportRestructuredText": true,
"python.analysis.typeCheckingMode": "basic"
}
}
I think The actual diagnostic is Edit: It works for me in
This seems to be the tracking issue for it python/mypy#16111 No rush on the review @binste, just thought I'd be able to make that tweak quickly |
Resolves vega#3455 (comment) Note: The other imports changes are simply to align with my other PRs in review
binste
left a comment
There was a problem hiding this comment.
Thanks for the explanations and the link to the mypy PR! LGTM :)
* refactor(typing): reduce type ignores in `api.py` * feat(typing): adds `_is_undefined` guard Direct copy from another PR, but is helpful here https://github.com/dangotbanned/altair/blob/d607c70824860ef3478d7d3996d26dc516d69369/altair/vegalite/v5/api.py#L504 * fix(typing): `ignore[index]` from #3455 * fix(typing): `[ignore[arg-type]` from #3452 * refactor(typing): use `_is_undefined` in some cases * refactor: reduce code duplication in `Chart.to_dict` * fix(typing): Recover `TopLevelMixin.resolve_` return types I removed these in 6adf564 due to how complex they were getting, but both `mypy` and `pyright` seem happy with this solution * fix(typing): narrow annotated types for `_check_if_valid_subspec` Following investigation during #3480 (comment) * refactor: remove unused `_wrapper_classes` argument from `SchemaBase` Fixes: - #3480 (comment) - #3480 (comment) - #3480 (comment)


Supporting PR to attach to #3454
Notes
Deprecation should be handled using a decorator recognized by static type checkers:
@warnings.deprecatedforsys.version_info >= (3, 13)@typing_extensions.deprecatedfor earlier versionsNote: need to see how these handle subclassingsubclassing seems to be unrecognized staticallyversionkeyword-only, required argumentaltair==x.y.zthis was introducedwarnings.warn&@utils.deprecation.deprecated@typing_extensions.deprecatedDemo
The screenshot below shows the differences in behaviour of each decorator:
This is the ideal situation, where a type checker can identify the deprecation :
https://github.com/dangotbanned/altair/blob/fe1917e3d4986dfa431f428146819622b83b6546/altair/vegalite/v5/api.py#L796-L805
Console output
Sample code block
At runtime, Sample code block outputs:
Output
Summary
@deprecatebut renaming to the prior@deprecated.@deprecateand the screenshot demo are referencing fe1917e which also has a class implementationalt.paramaltair/altair/vegalite/v5/api.py
Lines 448 to 482 in 7f05ecb
Rejected Ideas
Applying
@deprecatedto individual overloadsThis is a pretty interesting feature, but it comes with too many downsides.
Happy overload
Unhappy overload
Implementation
typing.get_overloads, writing some handler logictyping_extensionsdecoratorversionincludedwebdriverargument@overloadcode, which I don't think is warranted given the other issues