• Get Review Board
  • What's New
  • Products
  • Review Board Code review, image review, and document review
  • Documentation
  • Release Notes
  • Power Pack Enterprise integrations, reports, and enhanced document review
  • Try for 60 Days
  • Purchase
  • RBCommons Review Board as a Service, hosted by us
  • Pricing
  • RBTools Command line tools and Python API for Review Board
  • Documentation
  • Release Notes
  • Review Bot Automated code review, connecting tools you already use
  • Documentation
  • Release Notes
  • RB Gateway Manage Git and Mercurial repositories in your network
  • Documentation
  • Release Notes
  • Learn and Explore
  • What is Code Review?
  • Documentation
  • Frequently Asked Questions
  • Support Options
  • Third-Party Integrations
  • Demo
  • Review Board RBTools Power Pack Review Bot Djblets RB Gateway
    1. Djblets 4.x
    2. Version 5.x
    3. Version 4.x
    4. Version 3.x
    5. Version 2.x
    6. Version 2.0
    7. Version 1.0
    8. Version 0.9
    9. Djblets Documentation
    10. Module and Class References
    11. djblets.util.properties
  • Home
  • Guides
  • Avatar Services Guides
  • Writing Avatar Services
  • Extension Guides
  • Writing Extensions
  • Testing Extensions
  • Feature Checks Guides
  • Introduction to Feature Checks
  • Writing Features
  • Writing Feature Checkers
  • Testing with Feature Checks
  • Integration Guides
  • Supporting Integrations
  • Writing Integrations
  • Privacy Compliance Guides
  • Getting and Checking Consent
  • Working with Personally Identifiable Information
  • Service Integrations
  • reCAPTCHA Guides
  • Using reCAPTCHA
  • Registries Guides
  • Writing Registries
  • Web API Guides
  • Writing Web API Resources
  • Adding OAuth2 Support
  • Module and Class References
  • djblets
  • djblets.deprecation
  • djblets.auth.forms
  • djblets.auth.ratelimit
  • djblets.auth.signals
  • djblets.auth.util
  • djblets.auth.views
  • djblets.avatars.errors
  • djblets.avatars.forms
  • djblets.avatars.registry
  • djblets.avatars.services
  • djblets.avatars.services.base
  • djblets.avatars.services.fallback
  • djblets.avatars.services.file_upload
  • djblets.avatars.services.gravatar
  • djblets.avatars.services.url
  • djblets.avatars.settings
  • djblets.cache.backend
  • djblets.cache.backend_compat
  • djblets.cache.context_processors
  • djblets.cache.errors
  • djblets.cache.forwarding_backend
  • djblets.cache.serials
  • djblets.cache.synchronizer
  • djblets.conditions
  • djblets.conditions.choices
  • djblets.conditions.conditions
  • djblets.conditions.errors
  • djblets.conditions.operators
  • djblets.conditions.values
  • djblets.configforms.forms
  • djblets.configforms.mixins
  • djblets.configforms.pages
  • djblets.configforms.registry
  • djblets.configforms.views
  • djblets.datagrid.grids
  • djblets.db.backends.mysql.base
  • djblets.db.fields
  • djblets.db.fields.base64_field
  • djblets.db.fields.counter_field
  • djblets.db.fields.json_field
  • djblets.db.fields.modification_timestamp_field
  • djblets.db.fields.relation_counter_field
  • djblets.db.managers
  • djblets.db.query
  • djblets.db.validators
  • djblets.extensions.admin
  • djblets.extensions.errors
  • djblets.extensions.extension
  • djblets.extensions.forms
  • djblets.extensions.hooks
  • djblets.extensions.loaders
  • djblets.extensions.manager
  • djblets.extensions.middleware
  • djblets.extensions.models
  • djblets.extensions.packaging
  • djblets.extensions.resources
  • djblets.extensions.settings
  • djblets.extensions.signals
  • djblets.extensions.staticfiles
  • djblets.extensions.testing
  • djblets.extensions.testing.testcases
  • djblets.extensions.urls
  • djblets.extensions.views
  • djblets.extensions.templatetags.djblets_extensions
  • djblets.features
  • djblets.features.checkers
  • djblets.features.decorators
  • djblets.features.errors
  • djblets.features.feature
  • djblets.features.level
  • djblets.features.registry
  • djblets.features.testing
  • djblets.features.templatetags.features
  • djblets.feedview.views
  • djblets.feedview.templatetags.feedtags
  • djblets.forms.fields
  • djblets.forms.fieldsets
  • djblets.forms.forms
  • djblets.forms.forms.key_value_form
  • djblets.forms.widgets
  • djblets.gravatars
  • djblets.gravatars.templatetags.gravatars
  • djblets.http.middleware
  • djblets.http.responses
  • djblets.integrations.errors
  • djblets.integrations.forms
  • djblets.integrations.hooks
  • djblets.integrations.integration
  • djblets.integrations.manager
  • djblets.integrations.mixins
  • djblets.integrations.models
  • djblets.integrations.urls
  • djblets.integrations.views
  • djblets.log
  • djblets.log.middleware
  • djblets.log.siteconfig
  • djblets.log.urls
  • djblets.log.views
  • djblets.mail.dmarc
  • djblets.mail.message
  • djblets.mail.testing
  • djblets.mail.utils
  • djblets.markdown
  • djblets.markdown.extensions.escape_html
  • djblets.markdown.extensions.wysiwyg
  • djblets.markdown.extensions.wysiwyg_email
  • djblets.pipeline.compilers.es6
  • djblets.pipeline.compilers.less
  • djblets.pipeline.compilers.mixins
  • djblets.pipeline.compilers.rollup
  • djblets.pipeline.compilers.typescript
  • djblets.pipeline.settings
  • djblets.privacy.consent
  • djblets.privacy.consent.base
  • djblets.privacy.consent.common
  • djblets.privacy.consent.errors
  • djblets.privacy.consent.forms
  • djblets.privacy.consent.hooks
  • djblets.privacy.consent.registry
  • djblets.privacy.consent.tracker
  • djblets.privacy.models
  • djblets.privacy.pii
  • djblets.privacy.templatetags.djblets_privacy
  • djblets.recaptcha.mixins
  • djblets.recaptcha.siteconfig
  • djblets.recaptcha.templatetags.djblets_recaptcha
  • djblets.recaptcha.widgets
  • djblets.registries
  • djblets.registries.errors
  • djblets.registries.importer
  • djblets.registries.mixins
  • djblets.registries.registry
  • djblets.registries.signals
  • djblets.secrets
  • djblets.secrets.crypto
  • djblets.secrets.token_generators
  • djblets.secrets.token_generators.base
  • djblets.secrets.token_generators.legacy_sha1
  • djblets.secrets.token_generators.registry
  • djblets.secrets.token_generators.vendor_checksum
  • djblets.siteconfig
  • djblets.siteconfig.admin
  • djblets.siteconfig.context_processors
  • djblets.siteconfig.django_settings
  • djblets.siteconfig.forms
  • djblets.siteconfig.managers
  • djblets.siteconfig.middleware
  • djblets.siteconfig.models
  • djblets.siteconfig.signals
  • djblets.siteconfig.views
  • djblets.template.caches
  • djblets.template.context
  • djblets.template.loaders.conditional_cached
  • djblets.template.loaders.namespaced_app_dirs
  • djblets.testing.decorators
  • djblets.testing.testcases
  • djblets.testing.testrunners
  • djblets.urls.context_processors
  • djblets.urls.decorators
  • djblets.urls.patterns
  • djblets.urls.resolvers
  • djblets.urls.root
  • djblets.urls.staticfiles
  • djblets.util.compat.django.core.cache
  • djblets.util.compat.python.past
  • djblets.util.contextmanagers
  • djblets.util.dates
  • djblets.util.decorators
  • djblets.util.filesystem
  • djblets.util.functional
  • djblets.util.html
  • djblets.util.http
  • djblets.util.humanize
  • djblets.util.json_utils
  • djblets.util.properties
  • djblets.util.serializers
  • djblets.util.symbols
  • djblets.util.templatetags.djblets_deco
  • djblets.util.templatetags.djblets_email
  • djblets.util.templatetags.djblets_forms
  • djblets.util.templatetags.djblets_images
  • djblets.util.templatetags.djblets_js
  • djblets.util.templatetags.djblets_utils
  • djblets.util.typing
  • djblets.util.views
  • djblets.views.generic.base
  • djblets.views.generic.etag
  • djblets.webapi.auth
  • djblets.webapi.auth.backends
  • djblets.webapi.auth.backends.api_tokens
  • djblets.webapi.auth.backends.base
  • djblets.webapi.auth.backends.basic
  • djblets.webapi.auth.backends.oauth2_tokens
  • djblets.webapi.auth.views
  • djblets.webapi.decorators
  • djblets.webapi.encoders
  • djblets.webapi.errors
  • djblets.webapi.fields
  • djblets.webapi.managers
  • djblets.webapi.models
  • djblets.webapi.oauth2_scopes
  • djblets.webapi.resources
  • djblets.webapi.resources.base
  • djblets.webapi.resources.group
  • djblets.webapi.resources.registry
  • djblets.webapi.resources.root
  • djblets.webapi.resources.user
  • djblets.webapi.resources.mixins.api_tokens
  • djblets.webapi.resources.mixins.forms
  • djblets.webapi.resources.mixins.oauth2_tokens
  • djblets.webapi.resources.mixins.queries
  • djblets.webapi.responses
  • djblets.webapi.signals
  • djblets.webapi.testing
  • djblets.webapi.testing.decorators
  • djblets.webapi.testing.testcases
  • General Index
  • Python Module Index
  • Release Notes
  • This documentation covers Djblets 4.x. You can select a version above or view the latest documentation.

    djblets.util.properties¶

    Specialized descriptors/properties for classes.

    class BaseProperty[source]¶

    Bases: Generic[_StoredT]

    Base class for a custom property for a class.

    This is an optional base class that provides handy utilities that properties may need. For instance, being able to determine the name of the property’s attribute on a class.

    Changed in version 3.3: This now supports generics for typing, taking the type of the stored content.

    attr_name: str¶

    The name of the owning attribute.

    New in version 3.3.

    get_attr_name(instance: object) → str[source]¶

    Return the name of this property’s attribute.

    Deprecated since version 3.3: This has been replaced with attr_name, and will be removed in Djblets 5.0.

    Parameters:

    instance (object) – The instance owning this property.

    Returns:

    The name of this property on the instance.

    Return type:

    str

    __set_name__(owner: type, name: str) → None[source]¶

    Handle setting the attribute name for this property.

    New in version 3.3.

    Parameters:
    • owner (type, unused) – The class that owns the property.

    • name (str) – The attribute name for this property.

    __annotations__ = {'attr_name': 'str'}¶
    __orig_bases__ = (typing.Generic[~_StoredT],)¶
    __parameters__ = (~_StoredT,)¶
    class AliasProperty(prop_name: str, *, convert_to_func: ~typing.Optional[~typing.Callable[[~djblets.util.properties._AliasPropertySetT], ~typing.Any]] = None, convert_from_func: ~typing.Optional[~typing.Callable[[~typing.Any], ~djblets.util.properties._GetT]] = None, deprecated: bool = False, deprecation_warning: ~typing.Type[DeprecationWarning] = <class 'DeprecationWarning'>)[source]¶

    Bases: Generic[_GetT, _AliasPropertySetT], BaseProperty[Any]

    A property that aliases to another property or attribute.

    Alias properties are used to automatically retrieve from another property on access, or to set a value on another property. It’s useful when wanting to rename an attribute but continue to provide a deprecated version, or when creating an object that provides a set of compatibility attributes for use with legacy code.

    Alias properties can optionally emit a deprecation warning on use, in order to help in the process of migrating legacy code.

    Changed in version 3.3: This now supports generics for typing, taking the types to return on access, and types that can be set.

    Example

    class MyClass:
        new_prop: str
        old_prop: AliasProperty[int, str] = AliasProperty[int, str](
            'new_prop',
            convert_to_func=str,
            convert_from_func=int)
    

    Note that the explicit type declaration is important. Without it, type checkers may allow constructors to override the type.

    __init__(prop_name: str, *, convert_to_func: ~typing.Optional[~typing.Callable[[~djblets.util.properties._AliasPropertySetT], ~typing.Any]] = None, convert_from_func: ~typing.Optional[~typing.Callable[[~typing.Any], ~djblets.util.properties._GetT]] = None, deprecated: bool = False, deprecation_warning: ~typing.Type[DeprecationWarning] = <class 'DeprecationWarning'>) → None[source]¶

    Initialize the property.

    Changed in version 3.3: All arguments but prop_name must be provided as keyword arguments. This will be enforced in Djblets 5.0.

    Parameters:
    • prop_name (str) – The name of the property or attribute to read from and write to.

    • convert_to_func (callable, optional) – An optional function to call on a value before setting it on the aliased property name. This must take in the value as a parameter and return a value to set.

    • convert_from_func (callable, optional) – An optional function to call on a value after accessing it on the aliased property name and before returning to the caller. This must take in the value from the aliased property and return a value to return to the caller.

    • deprecated (bool, optional) – Whether to emit a deprecation warning when setting or accessing the property.

    • deprecation_warning (type) – The type of class to use for the deprecation warning. This should be a subclass of DeprecationWarning.

    prop_name: str¶

    The name of the property or attribute to read from and write to

    deprecated: bool¶

    Whether to emit a deprecation warning on access.

    deprecation_warning: Type[DeprecationWarning]¶

    The type of class to use for the deprecation warning.

    __set__(instance: object, value: _AliasPropertySetT) → None[source]¶

    Set a value on the property.

    This will convert the value (if convert_to_func was provided to this property) and set it on the aliased property.

    If this is a deprecated property, this will emit a warning.

    Parameters:
    • instance (object) – The instance owning this property.

    • value (object) – The value being set.

    __get__(instance: None, owner: Type[object]) → Self[source]¶
    __get__(instance: object, owner: Type[object]) → _GetT

    Return the value of the property.

    This will retrieve the value from the aliased property, converting it (if convert_from_func was provided to this property), and return it.

    If this is a deprecated property, this will emit a warning.

    Parameters:
    • instance (object) – The instance owning this property.

    • owner (type) – The instance’s class.

    Returns:

    The property value.

    Return type:

    object

    __annotations__ = {'attr_name': 'str', 'deprecated': 'bool', 'deprecation_warning': 'Type[DeprecationWarning]', 'prop_name': 'str'}¶
    __orig_bases__ = (typing.Generic[~_GetT, ~_AliasPropertySetT], djblets.util.properties.BaseProperty[typing.Any])¶
    __parameters__ = (~_GetT, ~_AliasPropertySetT)¶
    class TypedProperty(valid_types: Union[Type[_SetT], Sequence[Type[_SetT]]], *, default: Optional[_TypedPropertyGetT] = None, allow_none: bool = True)[source]¶

    Bases: Generic[_TypedPropertyGetT, _SetT], BaseProperty[_TypedPropertyGetT]

    A property that enforces type safety.

    This property will ensure that only values that are compatible with a given type can be set. This ensures type safety and helps catch errors early.

    Changed in version 3.3: This now supports generics for typing, taking the types to return on access, and types that can be set.

    Example

    class MyClass:
        optional_prop: TypedProperty[Optional[str], Optional[str]] =                    TypedProperty(str)
        required_to_set_prop: TypedProperty[Optional[int], int] =                    TypedProperty(int,
                          default=None
                          allow_none=False)
        never_none_prop: TypedProperty[int, int] =                    TypedProperty(int,
                          default=42,
                          allow_none=False)
    

    Note that the explicit type declaration is important. Without it, type checkers may allow constructors to override the type.

    __annotations__ = {'allow_none': 'bool', 'default': 'Optional[_TypedPropertyGetT]', 'valid_types': 'Tuple[Type[_SetT], ...]'}¶
    __orig_bases__ = (typing.Generic[~_TypedPropertyGetT, ~_SetT], djblets.util.properties.BaseProperty[~_TypedPropertyGetT])¶
    __parameters__ = (~_TypedPropertyGetT, ~_SetT)¶
    __init__(valid_types: Union[Type[_SetT], Sequence[Type[_SetT]]], *, default: Optional[_TypedPropertyGetT] = None, allow_none: bool = True) → None[source]¶

    Initialize the property.

    Changed in version 3.3: All arguments but prop_name must be provided as keyword arguments. This will be enforced in Djblets 5.0.

    Parameters:
    • valid_types (list of type) – The types of values that are permitted to be set.

    • default (object, optional) – The default value, if one is not set.

    • allow_none (bool, optional) – Whether None values are allowed to be set.

    valid_types: Tuple[Type[_SetT], ...]¶

    The types that are valid for this property.

    New values are checked against this at runtime.

    default: Optional[_TypedPropertyGetT]¶

    The default value for the property if one is not set.

    allow_none: bool¶

    Whether a None value is allowed to be set.

    __set__(instance: object, value: _SetT) → None[source]¶

    Set a value on the property.

    This will check if the value is of a valid type, and then set it on the instance.

    Parameters:
    • instance (object) – The instance owning this property.

    • value (object) – The value being set.

    Raises:

    TypeError – The value is not of a valid type.

    __get__(instance: None, owner: Type[object]) → Self[source]¶
    __get__(instance: object, owner: Type[object]) → _TypedPropertyGetT

    Return the value of the property.

    Parameters:
    • instance (object) – The instance owning this property.

    • owner (type) – The instance’s class.

    Returns:

    The property value.

    Return type:

    object

    get_descriptor_attr_name(descriptor, cls)[source]¶

    Return the name of a property/descriptor instance on a class.

    This will go through the class and all parent classes, looking for the property, and returning its attribute name. This is primarily intended to help with providing better error messages.

    Deprecated since version 3.3: This will be removed in Djblets 5.0. Callers should define a __set_name__() method on the descriptor instead.

    Parameters:
    • descriptor (object) – The instance of the property/descriptor. For a proper value to be returned, this must exist on cls.

    • cls (type) – The class owning the property.

    Returns:

    The name of the property/descriptor.

    Return type:

    str

    Keep up with the latest Review Board releases, security updates, and helpful information.

    About
    News
    Demo
    RBCommons Hosting
    Integrations
    Happy Users
    Support Options
    Documentation
    FAQ
    User Manual
    RBTools
    Administration Guide
    Power Pack
    Release Notes
    Downloads
    Review Board
    RBTools
    Djblets
    Power Pack
    Package Store
    PGP Signatures
    Contributing
    Bug Tracker
    Submit Patches
    Development Setup
    Wiki
    Follow Us
    Mailing Lists
    Reddit
    Twitter
    Mastodon
    Facebook
    YouTube

    Copyright © 2006-2025 Beanbag, Inc. All rights reserved.

    Terms of Service — Privacy Policy — AI Ethics Policy — Branding

    On this page

    • [Top]
    • BaseProperty
      • BaseProperty.attr_name
      • BaseProperty.get_attr_name()
      • BaseProperty.__set_name__()
      • BaseProperty.__annotations__
      • BaseProperty.__orig_bases__
      • BaseProperty.__parameters__
    • AliasProperty
      • AliasProperty.__init__()
      • AliasProperty.prop_name
      • AliasProperty.deprecated
      • AliasProperty.deprecation_warning
      • AliasProperty.__set__()
      • AliasProperty.__get__()
      • AliasProperty.__annotations__
      • AliasProperty.__orig_bases__
      • AliasProperty.__parameters__
    • TypedProperty
      • TypedProperty.__annotations__
      • TypedProperty.__orig_bases__
      • TypedProperty.__parameters__
      • TypedProperty.__init__()
      • TypedProperty.valid_types
      • TypedProperty.default
      • TypedProperty.allow_none
      • TypedProperty.__set__()
      • TypedProperty.__get__()
    • get_descriptor_attr_name()