Add properties for defining aliases and type enforcement.

Review Request #10495 — Created April 2, 2019 and submitted

chipx86
Djblets
release-2.0.x
10494
10496
djblets

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 disallowing None 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
Add properties for defining aliases and type enforcement.
Description From Last Updated

E501 line too long (80 > 79 characters)

reviewbotreviewbot
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

chipx86
chipx86
david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-2.0.x (328b328)
Loading...