Conversation
In #563, it became obvious that the bare string annotations are not just a problem when you want to use type hints, but also a problem with deferred evaluation of annotations in general. Python treats string literal annotations as forward references and may try to evaluate them later. This evaluation fails because the D-Bus signatures are not able to be evaluated as Python code. Now that we have proper annotation classes for D-Bus types, we can deprecate the use of bare string annotations to encourage users to switch to the new system. This becomes more urgent now that Python 3.14 has deferred evaluation of annotations enabled by default. We do want users to have plenty of time to migrate, so we make this deprecation period a few years long.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #586 +/- ##
==========================================
+ Coverage 85.66% 85.73% +0.07%
==========================================
Files 29 29
Lines 3480 3484 +4
Branches 601 601
==========================================
+ Hits 2981 2987 +6
+ Misses 308 307 -1
+ Partials 191 190 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
|
There was a problem hiding this comment.
Pull request overview
Deprecates bare string D-Bus signature annotations (which break under deferred evaluation of annotations) and encourages migration to typing.Annotated / dbus_fast.annotations types, adding warnings and updating docs/tests accordingly.
Changes:
- Emit a deprecation warning when string annotations are detected during annotation parsing.
- Update
dbus_method/dbus_propertydocumentation to showdbus_fast.annotationsusage and describe the deprecation. - Adjust tests to keep string-annotation coverage while asserting the new deprecation warning.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
src/dbus_fast/_private/util.py |
Adds deprecation warnings when parsing string annotations. |
src/dbus_fast/service.py |
Updates decorator docstrings to document Annotated-based typing and the new deprecation. |
docs/source/high-level-service/index.rst |
Updates high-level service docs to reference the new annotation approach. |
tests/service/test_methods.py |
Adds warning assertions while retaining string-annotation coverage. |
tests/client/test_methods.py |
Adds warning assertions while retaining string-annotation coverage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def deprecated_dbus_method(): | ||
| inner_wrapper = dbus_method() | ||
|
|
||
| def outer_wrapper(*args: Any) -> Any: | ||
| with pytest.warns( | ||
| DeprecationWarning, | ||
| match="String annotations are deprecated and support will be removed in the future. Use typing.Annotated with the appropriate annotation from dbus_fast.annotations instead.", | ||
| ): | ||
| return inner_wrapper(*args) | ||
|
|
||
| return outer_wrapper | ||
|
|
There was a problem hiding this comment.
This helper is duplicated in multiple test files. Consider moving it to a shared test utility (e.g., tests/util.py) or a pytest fixture to avoid repeating the warning message and logic in multiple places.
There was a problem hiding this comment.
It will be removed eventually and is not very big, so the duplication was intentional.
In #563, it became obvious that the bare string annotations are not just a problem when you want to use type hints, but also a problem with deferred evaluation of annotations in general. Python treats string literal annotations as forward references and may try to evaluate them later. This evaluation fails because the D-Bus signatures are not able to be evaluated as Python code.
Now that we have proper annotation classes for D-Bus types, we can deprecate the use of bare string annotations to encourage users to switch to the new system. This becomes more urgent now that Python 3.14 has deferred evaluation of annotations enabled by default.
We do want users to have plenty of time to migrate, so we make this deprecation period a few years long.