Skip to content

Commit 5075a16

Browse files
mjgjulian-smith-artifex-com
authored andcommitted
adjust to python 3.14
`typing.ByteString` has been deprecated since python 3.12 will be removed in python 3.14. For now, use a union type alias rather than identifying the minimal interface.
1 parent 0981155 commit 5075a16

File tree

5 files changed

+41
-10
lines changed

5 files changed

+41
-10
lines changed

src/__init__.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,15 @@ def _format_g(value, *, fmt='%g'):
419419

420420
format_g = _format_g
421421

422+
# ByteString is gone from typing in 3.14.
423+
# collections.abc.Buffer available from 3.12 only
424+
try:
425+
ByteString = typing.ByteString
426+
except AttributeError:
427+
ByteString = bytes | bytearray | memoryview
428+
422429
# Names required by class method typing annotations.
423-
OptBytes = typing.Optional[typing.ByteString]
430+
OptBytes = typing.Optional[ByteString]
424431
OptDict = typing.Optional[dict]
425432
OptFloat = typing.Optional[float]
426433
OptInt = typing.Union[int, None]
@@ -3982,7 +3989,7 @@ def delete_pages(self, *args, **kw):
39823989

39833990
def embfile_add(self,
39843991
name: str,
3985-
buffer_: typing.ByteString,
3992+
buffer_: ByteString,
39863993
filename: OptStr =None,
39873994
ufilename: OptStr =None,
39883995
desc: OptStr =None,
@@ -8285,7 +8292,7 @@ def add_circle_annot(self, rect: rect_like) -> Annot:
82858292
def add_file_annot(
82868293
self,
82878294
point: point_like,
8288-
buffer_: typing.ByteString,
8295+
buffer_: ByteString,
82898296
filename: str,
82908297
ufilename: OptStr =None,
82918298
desc: OptStr =None,
@@ -18382,7 +18389,7 @@ def get_text_length(text: str, fontname: str ="helv", fontsize: float =11, encod
1838218389
raise ValueError("Font '%s' is unsupported" % fontname)
1838318390

1838418391

18385-
def image_profile(img: typing.ByteString) -> dict:
18392+
def image_profile(img: ByteString) -> dict:
1838618393
""" Return basic properties of an image.
1838718394

1838818395
Args:

src/utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,20 @@
2929
rect_like = "rect_like"
3030
matrix_like = "matrix_like"
3131
quad_like = "quad_like"
32+
33+
# ByteString is gone from typing in 3.14.
34+
# collections.abc.Buffer available from 3.12 only
35+
try:
36+
ByteString = typing.ByteString
37+
except AttributeError:
38+
ByteString = bytes | bytearray | memoryview
39+
3240
AnyType = typing.Any
3341
OptInt = typing.Union[int, None]
3442
OptFloat = typing.Optional[float]
3543
OptStr = typing.Optional[str]
3644
OptDict = typing.Optional[dict]
37-
OptBytes = typing.Optional[typing.ByteString]
45+
OptBytes = typing.Optional[ByteString]
3846
OptSeq = typing.Optional[typing.Sequence]
3947

4048
"""

src_classic/fitz_old.i

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,20 @@ point_like = "point_like"
321321
rect_like = "rect_like"
322322
matrix_like = "matrix_like"
323323
quad_like = "quad_like"
324+
325+
# ByteString is gone from typing in 3.14.
326+
# collections.abc.Buffer available from 3.12 only
327+
try:
328+
ByteString = typing.ByteString
329+
except AttributeError:
330+
ByteString = bytes | bytearray | memoryview
331+
324332
AnyType = typing.Any
325333
OptInt = typing.Union[int, None]
326334
OptFloat = typing.Optional[float]
327335
OptStr = typing.Optional[str]
328336
OptDict = typing.Optional[dict]
329-
OptBytes = typing.Optional[typing.ByteString]
337+
OptBytes = typing.Optional[ByteString]
330338
OptSeq = typing.Optional[typing.Sequence]
331339

332340
try:
@@ -1342,7 +1350,7 @@ struct Document
13421350
self.xref_set_key(xref, "Params/ModDate", get_pdf_str(date))
13431351
return xref
13441352

1345-
def embfile_add(self, name: str, buffer: typing.ByteString,
1353+
def embfile_add(self, name: str, buffer: ByteString,
13461354
filename: OptStr =None,
13471355
ufilename: OptStr =None,
13481356
desc: OptStr =None,) -> None:
@@ -5964,7 +5972,7 @@ struct Page {
59645972

59655973

59665974
def add_file_annot(self, point: point_like,
5967-
buffer: typing.ByteString,
5975+
buffer: ByteString,
59685976
filename: str,
59695977
ufilename: OptStr =None,
59705978
desc: OptStr =None,

src_classic/helper-python.i

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ def planish_line(p1: point_like, p2: point_like) -> Matrix:
12451245
return Matrix(util_hor_matrix(p1, p2))
12461246

12471247

1248-
def image_profile(img: typing.ByteString) -> dict:
1248+
def image_profile(img: ByteString) -> dict:
12491249
""" Return basic properties of an image.
12501250
12511251
Args:

src_classic/utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,20 @@
2323
rect_like = "rect_like"
2424
matrix_like = "matrix_like"
2525
quad_like = "quad_like"
26+
27+
# ByteString is gone from typing in 3.14.
28+
# collections.abc.Buffer available from 3.12 only
29+
try:
30+
ByteString = typing.ByteString
31+
except AttributeError:
32+
ByteString = bytes | bytearray | memoryview
33+
2634
AnyType = typing.Any
2735
OptInt = typing.Union[int, None]
2836
OptFloat = typing.Optional[float]
2937
OptStr = typing.Optional[str]
3038
OptDict = typing.Optional[dict]
31-
OptBytes = typing.Optional[typing.ByteString]
39+
OptBytes = typing.Optional[ByteString]
3240
OptSeq = typing.Optional[typing.Sequence]
3341

3442
"""

0 commit comments

Comments
 (0)