Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define __getattribute__() instead of __getattr__() on slotted classes with cached properties #1291

Closed
wants to merge 2 commits into from

Commits on Jun 4, 2024

  1. Define __getattribute__() on slotted classes with cached properties

    Method `__getattribute__()` is documented as the "way to to actually get
    total control over attribute access" [1] so we change the implementation
    of slotted classes with cached properties by defining a
    `__getattribute__()` method instead of `__getattr__()` previously.
    
    [1]: https://docs.python.org/3/reference/datamodel.html#customizing-attribute-access
    
    Just changing that preserves the current behaviour, according to the
    test suite, but also makes sub-classing work better, e.g. when the
    subclass is not an attr-class and also defines a custom __getattr__() as
    evidenced in added test.
    
    In tests, we replace most custom `__getattr__()` definitions by
    equivalent `__getattribute__()` ones, except in regression tests where
    `__getattr__()` is explicitly involved. Also, in
    test_slots_with_multiple_cached_property_subclasses_works(), we replace
    the `if hasattr(super(), "__getattr__"):` by a `try:`/`except
    AttributeError:` as using `hasattr(..., "__getattribute__")` would be
    meaningless since `__getattribute__()` is always defined.
    
    Fix python-attrs#1288
    dlax committed Jun 4, 2024
    Configuration menu
    Copy the full SHA
    8bb16ee View commit details
    Browse the repository at this point in the history

Commits on Jul 13, 2024

  1. Configuration menu
    Copy the full SHA
    1d845e3 View commit details
    Browse the repository at this point in the history