44
55import json
66import re
7+ from contextlib import suppress
78from functools import wraps
89from typing import Any , Callable
910
@@ -72,10 +73,8 @@ def wrapper(obj_dict: dict[str, Any], symbol_id_map: dict[int, Any]) -> Any:
7273 # Assign object as parent on children.
7374 if "children" in obj_dict :
7475 for child in obj .children :
75- try :
76+ with suppress ( AttributeError ): # ints in groups
7677 child .parent = obj
77- except AttributeError :
78- pass # ints in groups
7978
8079 return obj
8180
@@ -505,7 +504,15 @@ def _load_group(obj_dict: dict) -> Group:
505504
506505
507506class TypedocDecoder (json .JSONDecoder ):
508- def __init__ (self , * args , ** kwargs ) -> None :
507+ """JSON decoder."""
508+
509+ def __init__ (self , * args : Any , ** kwargs : Any ) -> None :
510+ """Initialize the decoder.
511+
512+ Parameters:
513+ *args: Arguments passed to parent init method.
514+ *kwargs: Keyword arguments passed to parent init method.
515+ """
509516 kwargs ["object_hook" ] = self ._object_hook
510517 super ().__init__ (* args , ** kwargs )
511518 self ._symbol_map : dict [int , Any ] = {}
@@ -515,11 +522,6 @@ def _object_hook(self, obj_dict: dict[str, Any]) -> dict[str, Any] | str:
515522
516523 The [`json.loads`][] method walks the tree from bottom to top.
517524
518- Examples:
519- >>> import json
520- >>> from griffe.encoders import json_decoder
521- >>> json.loads(..., object_hook=json_decoder)
522-
523525 Parameters:
524526 obj_dict: The dictionary to decode.
525527
@@ -561,5 +563,3 @@ def _object_hook(self, obj_dict: dict[str, Any]) -> dict[str, Any] | str:
561563
562564 # Return dict as is.
563565 return obj_dict
564-
565- __all__ = ["json_decoder" ]
0 commit comments