-
-
Notifications
You must be signed in to change notification settings - Fork 671
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Add typehints for itk functional filters
These are helpful for type checkers, IDE's, and for building interfaces off the types. Since we do not know the default values until the constructor has been executed at runtime, use an Ellipsis as a placeholder per Python typehint stub convention. Types are reduced to equivalent Python types when possible, e.g. float, int, str, and Abstract Base Classes, abc's, like Sequence's. This adds a dependency on numpy>=1.20 and typing-extensions for numpy.typing.ArrayLike. We add type annotation for a number of types that cover most argument types -- more can gradually be added in the future. This also reduces runtime initialization of the functional docstring to compile time, which is helpful for performance. A few bugs were also addressed: we do not generate functional interfaces for abstract classes, and do not write out duplicate functional interfaces. Example result: from itk.support import helpers import itk.support.types as itkt from typing import Sequence, Tuple, Union @helpers.accept_array_like_xarray_torch def median_image_filter(*args: itkt.ImageLike, radius: Union[Sequence[int], int]=...,**kwargs)-> itkt.ImageSourceReturn: """Functional interface for MedianImageFilter""" import itk kwarg_typehints = { 'radius':radius } specified_kwarg_typehints = { k:v for (k,v) in kwarg_typehints.items() if kwarg_typehints[k] != ... } kwargs.update(specified_kwarg_typehints) instance = itk.MedianImageFilter.New(*args, **kwargs) return instance.__internal_call__() def median_image_filter_init_docstring(): import itk from itk.support import template_class filter_class = itk.ITKSmoothing.MedianImageFilter is_template = isinstance(filter_class, template_class.itkTemplate) if is_template: filter_object = filter_class.values()[0] else: filter_object = filter_class median_image_filter.__doc__ = filter_object.__doc__
- Loading branch information
Showing
10 changed files
with
313 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.