Skip to content

Commit

Permalink
src/__init__.py: avoid problems with type hint on Python-3.8.
Browse files Browse the repository at this point in the history
On Python 3.9, `collections.abc.Iterable[Page]` fails with
`TypeError: 'ABCMeta' object is not subscriptable`.
  • Loading branch information
julian-smith-artifex-com committed Apr 17, 2024
1 parent 6b7673f commit 272bbe2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5037,7 +5037,13 @@ def pagemode(self) -> str:
return rc[1][1:]
return "UseNone"

def pages(self, start: OptInt =None, stop: OptInt =None, step: OptInt =None) -> collections.abc.Iterable[Page]:
if sys.implementation.version < (3, 9):
# Appending `[Page]` causes `TypeError: 'ABCMeta' object is not subscriptable`.
_pages_ret = collections.abc.Iterable
else:
_pages_ret = collections.abc.Iterable[Page]

def pages(self, start: OptInt =None, stop: OptInt =None, step: OptInt =None) -> _pages_ret:
"""Return a generator iterator over a page range.

Arguments have the same meaning as for the range() built-in.
Expand Down

0 comments on commit 272bbe2

Please sign in to comment.