Add properties for defining aliases and type enforcement.
Review Request #10495 — Created April 2, 2019 and submitted
This introduces a couple of specialized properties that help with
deprecating older APIs and enforcing type safety with minimal effort.
AliasProperty
forwards on any property access (sets and gets) to
another attribute, optionally converting the new or existing value, and
optionally emitting a deprecation warning.
TypedProperty
takes one or more value types that are allowed to be
set, and checks any new values against those types, optionally allowing
or disallowingNone
values.These make use of a new function,
get_descriptor_attr_name()
, which
can locate the attribute of a descriptor/property in a class and return
the attribute name. It's used by these properties for error reporting
and for setting an attribute on a class instance based on the property's
name.
Unit tests passed.
Made use of these in some upcoming changes.
Summary | ID |
---|---|
7ad4bdb7b2fbb3f495227bd843019e62c93ef845 |
Description | From | Last Updated |
---|---|---|
E501 line too long (80 > 79 characters) |
reviewbot |