-
Notifications
You must be signed in to change notification settings - Fork 795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(typing): @deprecated
versioning, IDE highlighting
#3455
Conversation
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.deprecated
forsys.version_info >= (3, 13)
@typing_extensions.deprecated
for earlier versionsNote: need to see how these handle subclassingsubclassing seems to be unrecognized staticallyversion
keyword-only, required argumentaltair==x.y.z
this was introducedwarnings.warn
&@utils.deprecation.deprecated
@typing_extensions.deprecated
Demo
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
@deprecate
but renaming to the prior@deprecated
.@deprecate
and the screenshot demo are referencing fe1917e which also has a class implementationalt.param
altair/altair/vegalite/v5/api.py
Lines 448 to 482 in 7f05ecb
Rejected Ideas
Applying
@deprecated
to 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_extensions
decoratorversion
includedwebdriver
argument@overload
code, which I don't think is warranted given the other issues