Skip to content

Commit 71248f7

Browse files
cochang-dwalgritz
authored andcommitted
docs: Add type hints to Python docs (#4908)
Closes #4752 Add Python type hints into documentation, in places where example code defines a function. That ended up being just `src/doc/pythonbindings.rst`. I also updated `testsuite/runtest.py` and the functions in `testsuite/docs-examples-python/src/docs-examples-*.py`. While I was in `pythonbindings.rst`, I noticed a couple places with `py::method` (note the double colon). These lines didn't render in the docs, so I removed the extra colon to match other usage. I locally built the docs to make sure html looks good. I ran the tests with `ctest` and the tests ran, so I'm taking that as a sign that `runtest.py` still works. Signed-off-by: Connie Chang <[email protected]>
1 parent e382339 commit 71248f7

10 files changed

+84
-84
lines changed

src/doc/pythonbindings.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ described in detail in Section :ref:`sec-typedesc`, is replicated for Python.
7272
These names are also exported to the `OpenImageIO` namespace.
7373

7474

75-
.. py::method:: TypeDesc.TypeDesc(typename='unknown')
75+
.. py:method:: TypeDesc.TypeDesc(typename='unknown')
7676
7777
Construct a `TypeDesc` object the easy way: from a string description.
7878
If the type name is omitted, it will default to`UNKNOWN`.
@@ -97,7 +97,7 @@ described in detail in Section :ref:`sec-typedesc`, is replicated for Python.
9797
9898
9999
100-
.. py::method:: TypeDesc.TypeDesc(basetype=oiio.UNKNOWN, aggregate=oiio.SCALAR, vecsemantics=NOSEMANTICS, arraylen=0)
100+
.. py:method:: TypeDesc.TypeDesc(basetype=oiio.UNKNOWN, aggregate=oiio.SCALAR, vecsemantics=NOSEMANTICS, arraylen=0)
101101
102102
Construct a `TypeDesc` object the hard way: from individual enum tokens
103103
describing the base type, aggregate class, semantic hints, and array length.
@@ -751,7 +751,7 @@ function that opens a file and prints all the relevant header information:
751751
from OpenImageIO import ImageInput
752752
753753
# Print the contents of an ImageSpec
754-
def print_imagespec (spec, subimage=0, mip=0) :
754+
def print_imagespec (spec: ImageSpec, subimage: int=0, mip: int=0) :
755755
if spec.depth <= 1 :
756756
print (" resolution %dx%d%+d%+d" % (spec.width, spec.height, spec.x, spec.y))
757757
else :
@@ -787,7 +787,7 @@ function that opens a file and prints all the relevant header information:
787787
print (" ", i.name, "=", i.value)
788788
789789
790-
def poor_mans_iinfo (filename) :
790+
def poor_mans_iinfo (filename: str) :
791791
input = ImageInput.open (filename)
792792
if not input :
793793
print ('Could not open "' + filename + '"')
@@ -1243,7 +1243,7 @@ Example: Reading pixel values from a file to find min/max
12431243
#!/usr/bin/env python
12441244
import OpenImageIO as oiio
12451245
1246-
def find_min_max (filename) :
1246+
def find_min_max (filename: str) :
12471247
input = ImageInput.open (filename)
12481248
if not input :
12491249
print ('Could not open "' + filename + '"')
@@ -4041,8 +4041,8 @@ following boilerplate:
40414041
# Create an ImageBuf holding a n image of constant color, given the
40424042
# resolution, data format (defaulting to UINT8), fill value, and image
40434043
# origin.
4044-
def make_constimage (xres, yres, chans=3, format=oiio.UINT8, value=(0,0,0),
4045-
xoffset=0, yoffset=0) :
4044+
def make_constimage (xres: int, yres: int, chans: int=3, format: TypeDesc=oiio.UINT8, value: tuple[int, int, int]=(0,0,0),
4045+
xoffset: int=0, yoffset: int=0) -> ImageBuf:
40464046
spec = ImageSpec (xres,yres,chans,format)
40474047
spec.x = xoffset
40484048
spec.y = yoffset
@@ -4062,7 +4062,7 @@ what to do with it next.
40624062
40634063
# Save an ImageBuf to a given file name, with optional forced image format
40644064
# and error handling.
4065-
def write_image (image, filename, format=oiio.UNKNOWN) :
4065+
def write_image (image: ImageBuf, filename: str, format: TypeDesc=oiio.UNKNOWN) :
40664066
if not image.has_error :
40674067
image.write (filename, format)
40684068
if image.has_error :

testsuite/docs-examples-python/src/docs-examples-imagebuf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import OpenImageIO as oiio
1919
import numpy as np
2020

21-
def example1() :
21+
def example1() -> None:
2222
#
2323
# Example code fragment from the docs goes here.
2424
#

0 commit comments

Comments
 (0)