Skip to content

Commit

Permalink
Change typing.Optional[type] to type | None in docstrings
Browse files Browse the repository at this point in the history
Also improved docs for *colour* parameter of `PdfPage.render_base()`
  • Loading branch information
mara004 committed Aug 27, 2022
1 parent 1056e79 commit c1b3409
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/pypdfium2/_helpers/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def close(self):
def get_version(self):
"""
Returns:
typing.Optional[int]: The PDF version of the document (14 for 1.4, 15 for 1.5, ...),
int | None: The PDF version of the document (14 for 1.4, 15 for 1.5, ...),
or :data:`None` if the version could not be determined (e. g. because the document was created using :meth:`PdfDocument.new`).
"""
version = ctypes.c_int()
Expand All @@ -170,7 +170,7 @@ def save(self, buffer, version=None):
buffer (typing.BinaryIO):
A byte buffer to capture the data.
It may be any object implementing the ``write()`` method.
version (typing.Optional[int]):
version (int | None):
The PDF version to use, given as an integer (14 for 1.4, 15 for 1.5, ...).
If :data:`None`, PDFium will set a version automatically.
"""
Expand Down Expand Up @@ -202,7 +202,7 @@ def new_page(self, width, height, index=None):
Target page width (horizontal size).
height (float):
Target page height (vertical size).
index (typing.Optional[int]):
index (int | None):
Suggested zero-based index at which the page will be inserted.
If *index* is less or equal to zero, the page will be inserted at the beginning.
If *index* is :data:`None` or larger that the document's current last index, the page will be appended to the end.
Expand Down Expand Up @@ -394,7 +394,7 @@ def _render_base(
The order of results matches the order of given page indices.
Parameters:
page_indices (typing.Optional[typing.Sequence[int]]):
page_indices (typing.Sequence[int] | None):
A sequence of zero-based indices of the pages to render.
If :data:`None`, all pages will be included.
n_processes (int):
Expand Down
2 changes: 1 addition & 1 deletion src/pypdfium2/_helpers/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class OutlineItem:
String of the bookmark.
is_closed (bool):
If :data:`True`, child items shall be hidden by default.
page_index (int):
page_index (int | None):
Zero-based index of the page the bookmark points to.
view_mode (int):
A view mode constant (``PDFDEST_VIEW_...``) defining how the coordinates of *view_pos* shall be interpreted.
Expand Down
10 changes: 6 additions & 4 deletions src/pypdfium2/_helpers/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,13 @@ def render_base(
Amount in PDF canvas units to cut off from page borders (left, bottom, right, top).
Crop is applied after rotation.
colour (typing.Optional[ typing.Tuple[int, int, int, typing.Optional[int]] ]):
colour (typing.Tuple[int, int, int, int] | typing.Tuple[int, int, int] | None):
Page background colour. Defaults to white.
It can either be :data:`None`, or values of red, green, blue, and alpha ranging from 0 to 255.
If :data:`None`, the bitmap will not be filled with a colour, resulting in transparent background.
For RGB, 0 will include nothing of the colour in question, while 255 will completely include it. For Alpha, 0 means full transparency, while 255 means no transparency.
Otherwise, *colour* shall be a list of values for red, green, blue, and optionally alpha, ranging from 0 to 255.
If alpha is not given, it defaults to 255.
For RGB, 0 will include nothing of the colour in question, while 255 will fully include it.
For Alpha, 0 means full transparency, while 255 means no transparency.
annotations (bool):
Whether to render page annotations.
Expand All @@ -295,7 +297,7 @@ def render_base(
A list of item types that shall not be smoothed (text, image, path).
Returns:
(ctypes.c_ubyte_Array_N, str, (int, int)):
(``ctypes.c_ubyte_Array_%d``, str, (int, int)):
Ctypes array, colour format, and image size.
The colour format can be ``BGRA``, ``BGR``, or ``L``, depending on the parameters *colour* and *greyscale*.
Image size is given in pixels as a tuple of width and height.
Expand Down
2 changes: 1 addition & 1 deletion src/pypdfium2/_helpers/textpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def get_index(self, x, y, x_tol, y_tol):
y_tol (float): Vertical tolerance.
Returns:
typing.Optional[int]: The index of the character at or nearby the point (x, y).
int | None: The index of the character at or nearby the point (x, y).
May be :data:`None` if there is no character or an error occurred.
"""
index = pdfium.FPDFText_GetCharIndexAtPos(self._textpage, x, y, x_tol, y_tol)
Expand Down

0 comments on commit c1b3409

Please sign in to comment.