Skip to content

fix: replace invalid tuple type annotations with typing.Tuple - #713

Open
SukhmanH wants to merge 1 commit into
influxdata:masterfrom
SukhmanH:fix/invalid-tuple-type-annotations
Open

fix: replace invalid tuple type annotations with typing.Tuple#713
SukhmanH wants to merge 1 commit into
influxdata:masterfrom
SukhmanH:fix/invalid-tuple-type-annotations

Conversation

@SukhmanH

@SukhmanH SukhmanH commented Jul 25, 2026

Copy link
Copy Markdown

Closes #540

Proposed Changes

Briefly describe your proposed changes:

The batching callback signatures annotate conf as (str, str, str). A tuple of
types is not a valid type annotation, so any code copy-pasted from the README
fails type checking:

example.py:7: error: Syntax error in type annotation  [syntax]
example.py:7: note: Suggestion: Use Tuple[T1, ..., Tn] instead of (T1, ..., Tn)

This replaces the pattern with Tuple[str, str, str] in the 23 places it
appears:

  • influxdb_client/client/write_api.py — the _BatchItem.to_key_tuple() return
    annotation, which is the value actually passed to the callbacks
    (bucket, org, precision)
  • influxdb_client/client/util/multiprocessing_helper.py — the
    _success_callback / _error_callback / _retry_callback signatures
  • influxdb_client/client/influxdb_client.py and multiprocessing_helper.py
    docstring examples
  • examples/write_api_callbacks.py, examples/http_error_handling.py
  • tests/test_WriteApiBatching.py
  • README.md

typing.Tuple is used rather than the PEP 585 builtin tuple[...] because
setup.py still declares python_requires='>=3.7'. The copy-pasteable examples
also gained the matching from typing import Tuple import so they remain
runnable as-is, which was the original point of the issue.

This is annotation-only — no runtime behaviour changes. Verified:

  • mypy on the README snippet: 3 errors before, clean after
  • flake8 setup.py influxdb_client/ reports the same 2 pre-existing E721
    warnings in generated _sync/_async code as on master, and nothing new
  • pytest tests/test_WriteApiBatching.py — 24 passed

Checklist

  • CHANGELOG.md updated
  • Rebased/mergeable
  • A test has been added if appropriate
  • pytest tests completes successfully
  • Commit messages are conventional
  • Sign CLA (if not already signed)

The batching callback signatures used `(str, str, str)` as a type
annotation. A tuple of types is not a valid annotation, so mypy reports
"Syntax error in type annotation" on code copy-pasted from the README.

Replace with `Tuple[str, str, str]` in the callback signatures, the
`_BatchItem.to_key_tuple` return annotation, examples, tests and the
docs. `typing.Tuple` is used rather than the PEP 585 builtin `tuple`
because the package still supports Python 3.7.

Closes influxdata#540
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.38%. Comparing base (9ca599f) to head (55070e6).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #713   +/-   ##
=======================================
  Coverage   90.38%   90.38%           
=======================================
  Files          40       40           
  Lines        3546     3547    +1     
=======================================
+ Hits         3205     3206    +1     
  Misses        341      341           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SyntaxError in examples

3 participants