提交 3aae728d 编辑于 作者: Scott Wegner's avatar Scott Wegner 提交者: tensorflow-copybara
浏览文件

Move `attr.s` class type inference warning to correct usage block.

This was added recent to signal the future deprecation of converting `attr.s` classes to TFF types. However it was added to the wrong block. The intent is to deprecate conversion from a `attr.s` class *type*, but not a class *instance*.

PiperOrigin-RevId: 341702845
上级 c5bff444
......@@ -1004,6 +1004,12 @@ def _to_type_from_attrs(spec) -> Type:
"""Converts an `attr.s` class or instance to a `tff.Type`."""
if isinstance(spec, type):
# attrs class type, introspect the attributes for their type annotations.
# TODO(b/170486248): Deprecate support for converting `attr` classes.
warnings.warn(
'Deprecation warning: Converting `attr` classes to a federated type is '
'deprecated, use one of the other forms described in `tff.to_type()` '
'instead.', DeprecationWarning)
elements = [(a.name, a.type) for a in attr.fields(spec)]
missing_types = [n for (n, t) in elements if not t]
if missing_types:
......@@ -1015,12 +1021,6 @@ def _to_type_from_attrs(spec) -> Type:
else:
# attrs class instance, inspect the field values for instances convertible
# to types.
# TODO(b/170486248): Deprecate support for converting `attr` classes.
warnings.warn(
'Deprecation warning: Converting `attr` classes to a federated type is '
'deprecated, use one of the other forms described in `tff.to_type()` '
'instead.', DeprecationWarning)
elements = attr.asdict(
spec, dict_factory=collections.OrderedDict, recurse=False)
the_type = type(spec)
......
支持 Markdown
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册