Skip to content

Commit

Permalink
use Mapping from collections instead of typing
Browse files Browse the repository at this point in the history
Signed-off-by: Christian López Barrón <[email protected]>
  • Loading branch information
chrizzFTD committed Dec 15, 2024
1 parent 69830da commit 9757336
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions grill/cook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <https://en.wikipedia.org/wiki/Taxon>`_ for asset `taxonomy <https://en.wikipedia.org/wiki/Taxonomy>`_.
If an existing ``taxon`` with the provided name already exists in the `stage <https://graphics.pixar.com/usd/docs/api/class_usd_stage.html>`_, it is used.
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion grill/usd/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 9757336

Please sign in to comment.