diff --git a/grill/cook/__init__.py b/grill/cook/__init__.py index d89986a5..08001b98 100644 --- a/grill/cook/__init__.py +++ b/grill/cook/__init__.py @@ -25,6 +25,8 @@ from __future__ import annotations import types +# https://docs.python.org/3/whatsnew/3.10.html#pep-604-new-type-union-operator +# TODO: Remove when py-3.10+ is supported (for union types) import typing import logging import functools @@ -127,7 +129,7 @@ def fetch_stage(identifier: typing.Union[str, UsdAsset], context: Ar.ResolverCon return Usd.Stage.Open(layer, load=load) -def define_taxon(stage: Usd.Stage, name: str, *, references: tuple[Usd.Prim] = tuple(), id_fields: typing.Mapping[str, str] = types.MappingProxyType({})) -> Usd.Prim: +def define_taxon(stage: Usd.Stage, name: str, *, references: tuple[Usd.Prim] = tuple(), id_fields: collections.abc.Mapping[str, str] = types.MappingProxyType({})) -> Usd.Prim: """Define a new `taxon group `_ for asset `taxonomy `_. If an existing ``taxon`` with the provided name already exists in the `stage `_, it is used. @@ -455,12 +457,12 @@ def _root_asset(stage): def _get_id_fields(prim): if not (fields:=prim.GetAssetInfoByKey(_ASSETINFO_FIELDS_KEY)): raise ValueError(f"Missing or empty '{_FIELDS_KEY}' on '{_ASSETINFO_KEY}' asset info for {prim}. Got: {pformat(prim.GetAssetInfoByKey(_ASSETINFO_KEY))}") - if not isinstance(fields, typing.Mapping): + if not isinstance(fields, collections.abc.Mapping): raise TypeError(f"Expected mapping on key '{_FIELDS_KEY}' from {prim} on custom data key '{_ASSETINFO_KEY}'. Got instead {fields} with type: {type(fields)}") return fields -def _find_layer_matching(tokens: typing.Mapping, layers: collections.abc.Iterable[Sdf.Layer]) -> Sdf.Layer: +def _find_layer_matching(tokens: collections.abc.Mapping, layers: collections.abc.Iterable[Sdf.Layer]) -> Sdf.Layer: """Find the first layer matching the given identifier tokens. :raises ValueError: If none of the given layers match the provided tokens. diff --git a/grill/usd/__init__.py b/grill/usd/__init__.py index 14972172..72967d16 100644 --- a/grill/usd/__init__.py +++ b/grill/usd/__init__.py @@ -1,5 +1,7 @@ """Helpers for USD workflows which do not know anything about the pipeline.""" import enum +# https://docs.python.org/3/whatsnew/3.10.html#pep-604-new-type-union-operator +# TODO: Remove when py-3.10+ is supported (for union types) import typing import inspect import logging @@ -305,7 +307,7 @@ def is_target(arc): @contextlib.contextmanager -def _prim_tree_printer(predicate, prims_to_include: typing.Container = frozenset()): +def _prim_tree_printer(predicate, prims_to_include: abc.Container = frozenset()): prim_entry = Usd.Prim.GetName if predicate != Usd.PrimIsModel else lambda prim: f"{prim.GetName()} ({Usd.ModelAPI(prim).GetKind()})" class PrimTreePrinter(TreePrinter):