Skip to content

Commit d1d7873

Browse files
authored
Update typings and drop Python 3.5 (#11)
1 parent 90ad415 commit d1d7873

File tree

3 files changed

+12
-29
lines changed

3 files changed

+12
-29
lines changed

codecs/datetime.pyx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,7 @@ cdef timestamptz_encode(CodecContext settings, WriteBuffer buf, obj):
219219
buf.write_int64(pg_time64_negative_infinity)
220220
return
221221

222-
try:
223-
utc_dt = obj.astimezone(utc)
224-
except ValueError:
225-
# Python 3.5 doesn't like it when we call astimezone()
226-
# on naive datetime objects, so make it aware.
227-
utc_dt = obj.replace(tzinfo=_local_timezone()).astimezone(utc)
222+
utc_dt = obj.astimezone(utc)
228223

229224
delta = utc_dt - pg_epoch_datetime_utc
230225
cdef:

pgproto.pyi

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import codecs
2+
import typing
3+
import uuid
24

35
class CodecContext:
46
def get_text_codec(self) -> codecs.CodecInfo: ...
5-
def is_encoding_utf8(self) -> bool: ...
67

78
class ReadBuffer: ...
89
class WriteBuffer: ...
10+
class BufferError(Exception): ...
11+
12+
class UUID(uuid.UUID):
13+
def __init__(self, inp: typing.AnyStr) -> None: ...

types.py

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -238,24 +238,7 @@ def __len__(self) -> int:
238238
return self._bitlength
239239

240240

241-
if typing.TYPE_CHECKING or sys.version_info >= (3, 6):
242-
_PointBase = typing.Tuple[float, float]
243-
_BoxBase = typing.Tuple['Point', 'Point']
244-
_LineBase = typing.Tuple[float, float, float]
245-
_LineSegmentBase = typing.Tuple['Point', 'Point']
246-
_CircleBase = typing.Tuple['Point', float]
247-
else:
248-
# In Python 3.5, subclassing from typing.Tuple does not make the
249-
# subclass act like a tuple in certain situations (like starred
250-
# expressions)
251-
_PointBase = tuple
252-
_BoxBase = tuple
253-
_LineBase = tuple
254-
_LineSegmentBase = tuple
255-
_CircleBase = tuple
256-
257-
258-
class Point(_PointBase):
241+
class Point(typing.Tuple[float, float]):
259242
"""Immutable representation of PostgreSQL `point` type."""
260243

261244
__slots__ = ()
@@ -290,7 +273,7 @@ def y(self) -> float:
290273
return self[1]
291274

292275

293-
class Box(_BoxBase):
276+
class Box(typing.Tuple[Point, Point]):
294277
"""Immutable representation of PostgreSQL `box` type."""
295278

296279
__slots__ = ()
@@ -317,7 +300,7 @@ def low(self) -> Point:
317300
return self[1]
318301

319302

320-
class Line(_LineBase):
303+
class Line(typing.Tuple[float, float, float]):
321304
"""Immutable representation of PostgreSQL `line` type."""
322305

323306
__slots__ = ()
@@ -338,7 +321,7 @@ def C(self) -> float:
338321
return self[2]
339322

340323

341-
class LineSegment(_LineSegmentBase):
324+
class LineSegment(typing.Tuple[Point, Point]):
342325
"""Immutable representation of PostgreSQL `lseg` type."""
343326

344327
__slots__ = ()
@@ -421,7 +404,7 @@ def __init__(self, *points: typing.Sequence[float]) -> None:
421404
super().__init__(*points, is_closed=True)
422405

423406

424-
class Circle(_CircleBase):
407+
class Circle(typing.Tuple[Point, float]):
425408
"""Immutable representation of PostgreSQL `circle` type."""
426409

427410
__slots__ = ()

0 commit comments

Comments
 (0)