Prevent overriding cached attribute as property (#107657)

* Prevent overriding cached attribute as property

* Remove debug
This commit is contained in:
Erik Montnemery 2024-01-09 19:16:45 +01:00 committed by GitHub
parent ab6b9fe891
commit 9859306718
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 0 deletions

View file

@ -13,6 +13,7 @@ import logging
import math
import sys
from timeit import default_timer as timer
from types import FunctionType
from typing import (
TYPE_CHECKING,
Any,
@ -381,6 +382,9 @@ class CachedProperties(type):
# Check if an _attr_ class attribute exits and move it to __attr_. We check
# __dict__ here because we don't care about _attr_ class attributes in parents.
if attr_name in cls.__dict__:
attr = getattr(cls, attr_name)
if isinstance(attr, (FunctionType, property)):
raise TypeError(f"Can't override {attr_name} in subclass")
setattr(cls, private_attr_name, getattr(cls, attr_name))
annotations = cls.__annotations__
if attr_name in annotations: