From 769c9363882a61c0a3798a72cc9fe4fb1bf5734f Mon Sep 17 00:00:00 2001 From: PyGlove Authors Date: Sun, 2 Jul 2023 13:51:27 -0700 Subject: [PATCH] Internal changes. PiperOrigin-RevId: 545066179 --- pyglove/core/symbolic/base.py | 11 +++++++---- pyglove/core/symbolic/dict.py | 6 +++--- pyglove/core/typing/class_schema.py | 4 ++-- pyglove/core/typing/value_specs.py | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/pyglove/core/symbolic/base.py b/pyglove/core/symbolic/base.py index c5dd2c3..bbdad1d 100644 --- a/pyglove/core/symbolic/base.py +++ b/pyglove/core/symbolic/base.py @@ -669,8 +669,10 @@ def sym_rebind( Callable]] = None, # pylint: disable=g-bare-generic raise_on_no_change: bool = True, skip_notification: Optional[bool] = None, - **kwargs) -> 'Symbolic': + **kwargs, + ) -> 'Symbolic': """Mutates the sub-nodes of current object. Please see `rebind`.""" + assert Symbolic.DictType is not None if callable(path_value_pairs): path_value_pairs = get_rebind_dict(path_value_pairs, self) elif path_value_pairs is None: @@ -2130,6 +2132,7 @@ class A(pg.Object): * symbolic.Object for dict with '_type' property. * value itself. """ + assert Symbolic.DictType is not None if isinstance(json_value, Symbolic): return json_value @@ -2151,7 +2154,7 @@ class A(pg.Object): root_path=object_utils.KeyPath(i, root_path)) for i, v in enumerate(json_value[1:]) ]) - return Symbolic.ListType(json_value, **kwargs) # pylint: disable=not-callable + return Symbolic.ListType(json_value, **kwargs) # pytype: disable=not-callable # pylint: disable=not-callable elif isinstance(json_value, dict): if object_utils.JSONConvertible.TYPE_NAME_KEY not in json_value: return Symbolic.DictType.from_json(json_value, **kwargs) @@ -2394,7 +2397,7 @@ def _fn( if isinstance(value, dict): value_spec = pg_typing.ensure_value_spec( field.value, pg_typing.Dict(), path) - value = Symbolic.DictType( # pylint: disable=not-callable + value = Symbolic.DictType( # pytype: disable=not-callable # pylint: disable=not-callable value, value_spec=value_spec, allow_partial=allow_partial, @@ -2407,7 +2410,7 @@ def _fn( elif isinstance(value, list): value_spec = pg_typing.ensure_value_spec( field.value, pg_typing.List(pg_typing.Any()), path) - value = Symbolic.ListType( # pylint: disable=not-callable + value = Symbolic.ListType( # pytype: disable=not-callable # pylint: disable=not-callable value, value_spec=value_spec, allow_partial=allow_partial, diff --git a/pyglove/core/symbolic/dict.py b/pyglove/core/symbolic/dict.py index acfe4c2..25f9ad3 100644 --- a/pyglove/core/symbolic/dict.py +++ b/pyglove/core/symbolic/dict.py @@ -436,7 +436,7 @@ def sym_keys(self) -> Iterator[str]: yield key else: traversed = set() - for key_spec in self._value_spec.schema.keys(): + for key_spec in self._value_spec.schema.keys(): # pytype: disable=attribute-error if isinstance(key_spec, pg_typing.ConstStrKey) and key_spec in self: yield key_spec.text traversed.add(key_spec.text) @@ -780,7 +780,7 @@ def sym_jsonify( exclude_keys = set(exclude_keys or []) if self._value_spec and self._value_spec.schema: json_repr = dict() - matched_keys, _ = self._value_spec.schema.resolve(self.keys()) + matched_keys, _ = self._value_spec.schema.resolve(self.keys()) # pytype: disable=attribute-error for key_spec, keys in matched_keys.items(): # NOTE(daiyip): The key values of frozen field can safely be excluded # since they will be the same for a class. @@ -861,7 +861,7 @@ def _indent(text, indent): field_list = [] if self._value_spec and self._value_spec.schema: - matched_keys, unmatched = self._value_spec.schema.resolve(self.keys()) + matched_keys, unmatched = self._value_spec.schema.resolve(self.keys()) # pytype: disable=attribute-error assert not unmatched for key_spec, keys in matched_keys.items(): for key in keys: diff --git a/pyglove/core/typing/class_schema.py b/pyglove/core/typing/class_schema.py index 4ad6707..46554c2 100644 --- a/pyglove/core/typing/class_schema.py +++ b/pyglove/core/typing/class_schema.py @@ -975,7 +975,7 @@ def get_field(self, key: str) -> Optional[Field]: return None @property - def description(self) -> str: + def description(self) -> Optional[str]: """Returns the description for the schema.""" return self._description @@ -1126,7 +1126,7 @@ def validate(self, root_path=root_path) @property - def name(self) -> str: + def name(self) -> Optional[str]: """Name of this schema.""" return self._name diff --git a/pyglove/core/typing/value_specs.py b/pyglove/core/typing/value_specs.py index 4d9ae66..a091894 100644 --- a/pyglove/core/typing/value_specs.py +++ b/pyglove/core/typing/value_specs.py @@ -486,7 +486,7 @@ def min_value(self) -> typing.Optional[numbers.Number]: return self._min_value @property - def max_value(self) -> numbers.Number: + def max_value(self) -> typing.Optional[numbers.Number]: """Returns maximum value of acceptable values.""" return self._max_value