From c381fc818d886d468964344ad3b13f8ba5059ddd Mon Sep 17 00:00:00 2001 From: Justin Kerr Date: Wed, 10 Apr 2024 18:59:20 -0700 Subject: [PATCH] Fix custom elements nested under @property (#3066) * patch custom elements bug * Skip `cached_property` * fomrat * comment, type hint --------- Co-authored-by: Brent Yi --- nerfstudio/viewer/utils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/nerfstudio/viewer/utils.py b/nerfstudio/viewer/utils.py index c512e9169..0f5ead912 100644 --- a/nerfstudio/viewer/utils.py +++ b/nerfstudio/viewer/utils.py @@ -15,7 +15,8 @@ from __future__ import annotations from dataclasses import dataclass -from typing import Any, List, Literal, Optional, Tuple, Union +from functools import cached_property +from typing import Any, List, Literal, Optional, Tuple, Type, Union import numpy as np import torch @@ -109,7 +110,7 @@ def update_render_aabb( def parse_object( obj: Any, - type_check, + type_check: Type[Any], tree_stub: str, ) -> List[Tuple[str, Any]]: """ @@ -138,7 +139,8 @@ def parse_object( return [] ret = [] # get a list of the properties of the object, sorted by whether things are instances of type_check - obj_props = [(k, v) for k, v in vars(obj).items()] + # we skip cached properties, which can be expensive to call `getattr()` on! + obj_props = [(k, getattr(obj, k)) for k in dir(obj) if not isinstance(getattr(type(obj), k, None), cached_property)] for k, v in obj_props: if k[0] == "_": continue