From dbe2b1e2f1e54ae2cd161fb960ccaea9542f6a65 Mon Sep 17 00:00:00 2001 From: Przemek Denkiewicz Date: Tue, 16 Jul 2024 13:05:44 +0200 Subject: [PATCH 1/3] Remove normalize method from TemporalType This code has been dead/broken since 2b9ca0c2e59496e168907fec1df7a50f26976dce --- trino/types.py | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/trino/types.py b/trino/types.py index 429794a9..0807c2fc 100644 --- a/trino/types.py +++ b/trino/types.py @@ -5,8 +5,6 @@ from decimal import Decimal from typing import Any, Dict, Generic, List, Optional, Tuple, TypeVar, Union, cast -from dateutil import tz - PythonTemporalType = TypeVar("PythonTemporalType", bound=Union[time, datetime]) POWERS_OF_TEN: Dict[int, Decimal] = {i: Decimal(10**i) for i in range(0, 13)} MAX_PYTHON_TEMPORAL_PRECISION_POWER = 6 @@ -39,11 +37,6 @@ def round_to(self, precision: int) -> TemporalType[PythonTemporalType]: if digits > precision: rounding_factor = POWERS_OF_TEN[precision] rounded = remaining_fractional_seconds.quantize(Decimal(1 / rounding_factor)) - if rounded == rounding_factor: - return self.new_instance( - self.normalize(self.add_time_delta(timedelta(seconds=1))), - Decimal(0) - ) return self.new_instance(self._whole_python_temporal_value, rounded) return self @@ -54,13 +47,6 @@ def add_time_delta(self, time_delta: timedelta) -> PythonTemporalType: """ pass - def normalize(self, value: PythonTemporalType) -> PythonTemporalType: - """ - If `add_time_delta` results in value crossing DST boundaries, this method should - return a normalized version of the value to account for it. - """ - return value - class Time(TemporalType[time]): def new_instance(self, value: time, fraction: Decimal) -> TemporalType[time]: @@ -100,13 +86,6 @@ class TimestampWithTimeZone(Timestamp, TemporalType[datetime]): def new_instance(self, value: datetime, fraction: Decimal) -> TimestampWithTimeZone: return TimestampWithTimeZone(value, fraction) - def normalize(self, value: datetime) -> datetime: - if tz.datetime_ambiguous(value): - # This appears to be dead code since tzinfo doesn't actually have a `normalize` method. - # TODO: Fix this or remove. (https://github.com/trinodb/trino-python-client/issues/449) - return self._whole_python_temporal_value.tzinfo.normalize(value) # type: ignore - return value - class NamedRowTuple(Tuple[Any, ...]): """Custom tuple class as namedtuple doesn't support missing or duplicate names""" From 2410e3b70348dd507c9e36e534c3a51b5cae9b7f Mon Sep 17 00:00:00 2001 From: Przemek Denkiewicz Date: Tue, 6 Aug 2024 13:21:41 +0200 Subject: [PATCH 2/3] Fix types-all installation failure in pre-commit --- .pre-commit-config.yaml | 2 -- setup.cfg | 1 + trino/auth.py | 10 +++++----- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a781ab8c..321f6e47 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,8 +10,6 @@ repos: hooks: - id: "mypy" name: "Python: types" - additional_dependencies: - - "types-all" - repo: https://github.com/pycqa/isort rev: "5.13.2" diff --git a/setup.cfg b/setup.cfg index 372d84b0..c7cc318a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -18,6 +18,7 @@ disallow_untyped_defs = true ignore_missing_imports = true no_implicit_optional = true warn_unused_ignores = true +disable_error_code = import-untyped [mypy-tests.*,trino.client,trino.dbapi,trino.sqlalchemy.*] ignore_errors = true diff --git a/trino/auth.py b/trino/auth.py index 5b7b20ff..bf9b4b3b 100644 --- a/trino/auth.py +++ b/trino/auth.py @@ -388,7 +388,7 @@ def __call__(self, r: PreparedRequest) -> PreparedRequest: if token is not None: r.headers['Authorization'] = "Bearer " + token - r.register_hook('response', self._authenticate) # type: ignore + r.register_hook('response', self._authenticate) return r @@ -450,8 +450,8 @@ def _attempt_oauth(self, response: Response, **kwargs: Any) -> None: def _retry_request(self, response: Response, **kwargs: Any) -> Optional[Response]: request = response.request.copy() - extract_cookies_to_jar(request._cookies, response.request, response.raw) # type: ignore - request.prepare_cookies(request._cookies) # type: ignore + extract_cookies_to_jar(request._cookies, response.request, response.raw) + request.prepare_cookies(request._cookies) host = self._determine_host(response.request.url) user = self._determine_user(request.headers) @@ -459,7 +459,7 @@ def _retry_request(self, response: Response, **kwargs: Any) -> Optional[Response token = self._get_token_from_cache(key) if token is not None: request.headers['Authorization'] = "Bearer " + token - retry_response = response.connection.send(request, **kwargs) # type: ignore + retry_response = response.connection.send(request, **kwargs) retry_response.history.append(response) retry_response.request = request return retry_response @@ -468,7 +468,7 @@ def _get_token(self, token_server: str, response: Response, **kwargs: Any) -> st attempts = 0 while attempts < self.MAX_OAUTH_ATTEMPTS: attempts += 1 - with response.connection.send(Request( # type: ignore + with response.connection.send(Request( method='GET', url=token_server).prepare(), **kwargs) as response: if response.status_code == 200: token_response = json.loads(response.text) From f0a5305e5eccaa2e774f6292b9908d9229a2a79b Mon Sep 17 00:00:00 2001 From: Przemek Denkiewicz Date: Tue, 6 Aug 2024 14:28:33 +0200 Subject: [PATCH 3/3] Pin krb5 version to 0.5.1 Due to the compability issue with krb5 newest release. --- setup.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 061f3849..2047b415 100755 --- a/setup.py +++ b/setup.py @@ -27,7 +27,10 @@ readme = f.read() kerberos_require = ["requests_kerberos"] -gssapi_require = ["requests_gssapi"] +gssapi_require = ["" + "requests_gssapi", + # PyPy compatibility issue https://github.com/jborean93/pykrb5/issues/49 + "krb5 == 0.5.1"] sqlalchemy_require = ["sqlalchemy >= 1.3"] external_authentication_token_cache_require = ["keyring"]