Skip to content
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

Remove normalize method from TemporalType #472

Merged
merged 3 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
10 changes: 5 additions & 5 deletions trino/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -450,16 +450,16 @@ 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)
key = self._construct_cache_key(host, user)
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
Expand All @@ -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)
Expand Down
21 changes: 0 additions & 21 deletions trino/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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]:
Expand Down Expand Up @@ -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"""
Expand Down