• 
      

    Add typing for condition values.

    Review Request #14264 — Created Dec. 11, 2024 and submitted

    Information

    Djblets
    release-5.x

    Reviewers

    This updates djblets.conditions.values to support typing.
    BaseConditionValueField and ConditionValueFormField are now
    generics, accepting a type that the fields manage. These types are
    accepted in serialize_value() and returned in deserialize_value().
    Other value subclasses (for model values) also take a type.

    If a type is not provided, these default to Any. This is available as
    part of PEP 696 and a compatible typing_extensions.

    Some Python 2.7-safe code has been removed, cleaning up some tests and
    implementation code.

    This is the first step in making condition support type-safe, and
    modernizing some of the APIs for better type compliance.

    Unit tests pass.

    Summary ID
    Add typing for condition values.
    This updates `djblets.conditions.values` to support typing. `BaseConditionValueField` and `ConditionValueFormField` are now generics, accepting a type that the fields manage. These types are accepted in `serialize_value()` and returned in `deserialize_value()`. Other value subclasses (for model values) also take a type. If a type is not provided, these default to `Any`. This is available as part of PEP 696 and a compatible ``typing_extensions``. Some Python 2.7-safe code has been removed, cleaning up some tests and implementation code. This is the first step in making condition support type-safe, and modernizing some of the APIs for better type compliance.
    d7f333c502acba77fda42c20cbfdd89ee5f781c0
    Description From Last Updated

    This can just be TypeVar('_T')

    daviddavid
    maubin
    1. Ship It!
    2. 
        
    david
    1. 
        
    2. djblets/conditions/values.py (Diff revision 1)
       
       
       
       
      Show all issues

      This can just be TypeVar('_T')

      1. I can get rid of the bound, but default defaults to NoDefault and has to be explicitly provided to allow generics with a default.

      2. ok, sounds good.

      3. Turns out I have to keep the bound. Any and None are different things, and removing the bound results in typing errors.

    3. 
        
    chipx86
    Review request changed
    Status:
    Completed
    Change Summary:
    Pushed to release-5.x (d317571)