napari.types

Classes

ArrayBase

alias of numpy.ndarray

Path

PurePath subclass that can make system calls.

SampleDict

TracebackType

alias of types.TracebackType

partial

partial(func, *args, **keywords) - new function with partial application of the given arguments and keywords.

Functions

napari.types.ImageData(x)
napari.types.LabelsData(x)
napari.types.LayerDataTuple(x)
napari.types.NewType(name, tp)[source]

NewType creates simple unique types with almost zero runtime overhead. NewType(name, tp) is considered a subtype of tp by static type checkers. At runtime, NewType(name, tp) returns a dummy function that simply returns its argument. Usage:

UserId = NewType('UserId', int)

def name_by_id(user_id: UserId) -> str:
    ...

UserId('user')          # Fails type check

name_by_id(42)          # Fails type check
name_by_id(UserId(42))  # OK

num = UserId(5) + 1     # type: int
napari.types.PointsData(x)
napari.types.ShapesData(x)
napari.types.SurfaceData(x)
napari.types.TracksData(x)
napari.types.TypedDict(typename, fields=None, /, *, total=True, **kwargs)[source]

A simple typed namespace. At runtime it is equivalent to a plain dict.

TypedDict creates a dictionary type that expects all of its instances to have a certain set of keys, where each key is associated with a value of a consistent type. This expectation is not checked at runtime but is only enforced by type checkers. Usage:

class Point2D(TypedDict):
    x: int
    y: int
    label: str

a: Point2D = {'x': 1, 'y': 2, 'label': 'good'}  # OK
b: Point2D = {'z': 3, 'label': 'bad'}           # Fails type check

assert Point2D(x=1, y=2, label='first') == dict(x=1, y=2, label='first')

The type info can be accessed via the Point2D.__annotations__ dict, and the Point2D.__required_keys__ and Point2D.__optional_keys__ frozensets. TypedDict supports two additional equivalent forms:

Point2D = TypedDict('Point2D', x=int, y=int, label=str)
Point2D = TypedDict('Point2D', {'x': int, 'y': int, 'label': str})

By default, all keys must be present in a TypedDict. It is possible to override this by specifying totality. Usage:

class point2D(TypedDict, total=False):
    x: int
    y: int

This means that a point2D TypedDict can have any of the keys omitted.A type checker is only expected to support a literal False or True as the value of the total argument. True is the default, and makes all items defined in the class body be required.

The class syntax is only supported in Python 3.6+, while two other syntax forms work for Python 2.7 and 3.2+

napari.types.VectorsData(x)
napari.types.image_reader_to_layerdata_reader(func)[source]

Convert a PathLike -> ArrayLike function to a PathLike -> LayerData.

Parameters

func (Callable[[PathLike], ArrayLike]) – A function that accepts a string or list of strings, and returns an ArrayLike.

Returns

reader_function – A function that accepts a string or list of strings, and returns data as a list of LayerData: List[Tuple[ArrayLike]]

Return type

Callable[[PathLike], List[LayerData]]

napari.types.wraps(wrapped, assigned=('__module__', '__name__', '__qualname__', '__doc__', '__annotations__'), updated=('__dict__',))[source]

Decorator factory to apply update_wrapper() to a wrapper function

Returns a decorator that invokes update_wrapper() with the decorated function as the wrapper argument and the arguments to wraps() as the remaining arguments. Default arguments are as for update_wrapper(). This is a convenience function to simplify applying partial() to update_wrapper().