diff --git a/CHANGELOG.md b/CHANGELOG.md index 98a37713..67c678fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Bug Fixes 1. [#706](https://github.com/influxdata/influxdb-client-python/pull/706): Use logger instead logging. +1. [#540](https://github.com/influxdata/influxdb-client-python/issues/540): Replace invalid tuple type annotations `(str, str, str)` with `Tuple[str, str, str]` in batching callbacks, examples and docs. 1. [#686](https://github.com/influxdata/influxdb-client-python/issues/686): Stop `default_tags` from one client leaking into other clients' `WriteApi` (shared mutable default `PointSettings`). ## 1.50.0 [2026-01-23] diff --git a/README.md b/README.md index fa9fe8a8..fdcf4c43 100644 --- a/README.md +++ b/README.md @@ -1183,19 +1183,21 @@ The only exception is **batching** `WriteAPI` (for more info see [Batching](#bat This is because this API runs in the `background` in a `separate` thread and isn't possible to directly return underlying exceptions. ``` python +from typing import Tuple + from influxdb_client import InfluxDBClient from influxdb_client.client.exceptions import InfluxDBError class BatchingCallback(object): - def success(self, conf: (str, str, str), data: str): + def success(self, conf: Tuple[str, str, str], data: str): print(f"Written batch: {conf}, data: {data}") - def error(self, conf: (str, str, str), data: str, exception: InfluxDBError): + def error(self, conf: Tuple[str, str, str], data: str, exception: InfluxDBError): print(f"Cannot write batch: {conf}, data: {data} due: {exception}") - def retry(self, conf: (str, str, str), data: str, exception: InfluxDBError): + def retry(self, conf: Tuple[str, str, str], data: str, exception: InfluxDBError): print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}") diff --git a/examples/http_error_handling.py b/examples/http_error_handling.py index c125a7ff..5f5bb5f9 100644 --- a/examples/http_error_handling.py +++ b/examples/http_error_handling.py @@ -11,7 +11,7 @@ """ import asyncio import os -from typing import MutableMapping +from typing import MutableMapping, Tuple from influxdb_client import InfluxDBClient from influxdb_client.client.exceptions import InfluxDBError @@ -47,14 +47,14 @@ def __str__(self): # To encapsulate functions used in batch writing class BatchCB(object): - def success(self, conf: (str, str, str), data: str): + def success(self, conf: Tuple[str, str, str], data: str): print(f"Write success: {conf}, data: {data}") - def error(self, conf: (str, str, str), data: str, exception: InfluxDBError): + def error(self, conf: Tuple[str, str, str], data: str, exception: InfluxDBError): print(f"\nBatch -> Write failed: {conf}, data: {data}, error: {exception.message}") report_headers(exception.headers) - def retry(self, conf: (str, str, str), data: str, exception: InfluxDBError): + def retry(self, conf: Tuple[str, str, str], data: str, exception: InfluxDBError): print(f"Write failed but retryable: {conf}, data: {data}, error: {exception}") diff --git a/examples/write_api_callbacks.py b/examples/write_api_callbacks.py index 560fb3c1..23960007 100644 --- a/examples/write_api_callbacks.py +++ b/examples/write_api_callbacks.py @@ -2,6 +2,8 @@ How to use WriteApi's callbacks to notify about state of background batches. """ +from typing import Tuple + from influxdb_client import InfluxDBClient, Point from influxdb_client.client.exceptions import InfluxDBError @@ -22,15 +24,15 @@ class BatchingCallback(object): - def success(self, conf: (str, str, str), data: str): + def success(self, conf: Tuple[str, str, str], data: str): """Successfully writen batch.""" print(f"Written batch: {conf}, data: {data}") - def error(self, conf: (str, str, str), data: str, exception: InfluxDBError): + def error(self, conf: Tuple[str, str, str], data: str, exception: InfluxDBError): """Unsuccessfully writen batch.""" print(f"Cannot write batch: {conf}, data: {data} due: {exception}") - def retry(self, conf: (str, str, str), data: str, exception: InfluxDBError): + def retry(self, conf: Tuple[str, str, str], data: str, exception: InfluxDBError): """Retryable error.""" print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}") diff --git a/influxdb_client/client/influxdb_client.py b/influxdb_client/client/influxdb_client.py index 200536fd..71466e7b 100644 --- a/influxdb_client/client/influxdb_client.py +++ b/influxdb_client/client/influxdb_client.py @@ -240,19 +240,21 @@ def write_api(self, write_options=WriteOptions(), point_settings=None, **kwargs) .. code-block:: python + from typing import Tuple + from influxdb_client import InfluxDBClient from influxdb_client.client.exceptions import InfluxDBError class BatchingCallback(object): - def success(self, conf: (str, str, str), data: str): + def success(self, conf: Tuple[str, str, str], data: str): print(f"Written batch: {conf}, data: {data}") - def error(self, conf: (str, str, str), data: str, exception: InfluxDBError): + def error(self, conf: Tuple[str, str, str], data: str, exception: InfluxDBError): print(f"Cannot write batch: {conf}, data: {data} due: {exception}") - def retry(self, conf: (str, str, str), data: str, exception: InfluxDBError): + def retry(self, conf: Tuple[str, str, str], data: str, exception: InfluxDBError): print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}") diff --git a/influxdb_client/client/util/multiprocessing_helper.py b/influxdb_client/client/util/multiprocessing_helper.py index 41530a23..db4eaa39 100644 --- a/influxdb_client/client/util/multiprocessing_helper.py +++ b/influxdb_client/client/util/multiprocessing_helper.py @@ -6,6 +6,7 @@ """ import logging import multiprocessing +from typing import Tuple from influxdb_client import InfluxDBClient, WriteOptions from influxdb_client.client.exceptions import InfluxDBError @@ -13,17 +14,17 @@ logger = logging.getLogger('influxdb_client.client.util.multiprocessing_helper') -def _success_callback(conf: (str, str, str), data: str): +def _success_callback(conf: Tuple[str, str, str], data: str): """Successfully writen batch.""" logger.debug(f"Written batch: {conf}, data: {data}") -def _error_callback(conf: (str, str, str), data: str, exception: InfluxDBError): +def _error_callback(conf: Tuple[str, str, str], data: str, exception: InfluxDBError): """Unsuccessfully writen batch.""" logger.debug(f"Cannot write batch: {conf}, data: {data} due: {exception}") -def _retry_callback(conf: (str, str, str), data: str, exception: InfluxDBError): +def _retry_callback(conf: Tuple[str, str, str], data: str, exception: InfluxDBError): """Retryable error.""" logger.debug(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}") @@ -81,6 +82,8 @@ def main(): How to handle batch events: .. code-block:: python + from typing import Tuple + from influxdb_client import WriteOptions from influxdb_client.client.exceptions import InfluxDBError from influxdb_client.client.util.multiprocessing_helper import MultiprocessingWriter @@ -88,13 +91,13 @@ def main(): class BatchingCallback(object): - def success(self, conf: (str, str, str), data: str): + def success(self, conf: Tuple[str, str, str], data: str): print(f"Written batch: {conf}, data: {data}") - def error(self, conf: (str, str, str), data: str, exception: InfluxDBError): + def error(self, conf: Tuple[str, str, str], data: str, exception: InfluxDBError): print(f"Cannot write batch: {conf}, data: {data} due: {exception}") - def retry(self, conf: (str, str, str), data: str, exception: InfluxDBError): + def retry(self, conf: Tuple[str, str, str], data: str, exception: InfluxDBError): print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}") diff --git a/influxdb_client/client/write_api.py b/influxdb_client/client/write_api.py index ea9fb7b5..bc886835 100644 --- a/influxdb_client/client/write_api.py +++ b/influxdb_client/client/write_api.py @@ -9,7 +9,7 @@ from enum import Enum from random import random from time import sleep -from typing import Union, Any, Iterable, NamedTuple +from typing import Union, Any, Iterable, NamedTuple, Tuple import reactivex as rx from reactivex import operators as ops, Observable @@ -171,7 +171,7 @@ def __init__(self, key: _BatchItemKey, data, size=1) -> None: self.size = size pass - def to_key_tuple(self) -> (str, str, str): + def to_key_tuple(self) -> Tuple[str, str, str]: return self.key.bucket, self.key.org, self.key.precision def __str__(self) -> str: diff --git a/tests/test_WriteApiBatching.py b/tests/test_WriteApiBatching.py index 8befd7e5..96f01842 100644 --- a/tests/test_WriteApiBatching.py +++ b/tests/test_WriteApiBatching.py @@ -6,6 +6,7 @@ import time import unittest from collections import namedtuple +from typing import Tuple import httpretty import pytest @@ -582,7 +583,7 @@ def __init__(self): self.conf = None self.data = None - def __call__(self, conf: (str, str, str), data: str): + def __call__(self, conf: Tuple[str, str, str], data: str): self.conf = conf self.data = data @@ -617,7 +618,7 @@ def __init__(self): self.data = None self.error = None - def __call__(self, conf: (str, str, str), data: str, error: InfluxDBError): + def __call__(self, conf: Tuple[str, str, str], data: str, error: InfluxDBError): self.conf = conf self.data = data self.error = error @@ -657,7 +658,7 @@ def __init__(self): self.data = None self.error = None - def __call__(self, conf: (str, str, str), data: str, error: InfluxDBError): + def __call__(self, conf: Tuple[str, str, str], data: str, error: InfluxDBError): self.conf = conf self.data = data self.error = error @@ -704,7 +705,7 @@ def __init__(self): self.data = None self.error = None - def __call__(self, conf: (str, str, str), data: str, error: InfluxDBError): + def __call__(self, conf: Tuple[str, str, str], data: str, error: InfluxDBError): self.count += 1 self.conf = conf self.data = data