diff --git a/pydantic/fields.py b/pydantic/fields.py index c48e4c4c7d..fabca2e345 100644 --- a/pydantic/fields.py +++ b/pydantic/fields.py @@ -970,6 +970,18 @@ class ComputedFieldInfo: repr: bool +def _wrapped_property_is_private(property_: cached_property | property) -> bool: # type: ignore + """Returns true if provided property is private, False otherwise.""" + wrapped_name: str = '' + + if isinstance(property_, property): + wrapped_name = getattr(property_.fget, '__name__', '') + elif isinstance(property_, cached_property): # type: ignore + wrapped_name = getattr(property_.func, '__name__', '') # type: ignore + + return wrapped_name.startswith('_') and not wrapped_name.startswith('__') + + # this should really be `property[T], cached_proprety[T]` but property is not generic unlike cached_property # See https://github.com/python/typing/issues/985 and linked issues PropertyT = typing.TypeVar('PropertyT') @@ -995,18 +1007,6 @@ def computed_field(__func: PropertyT) -> PropertyT: ... -def _wrapped_property_is_private(property_: cached_property | property) -> bool: # type: ignore - """Returns true if provided property is private, False otherwise.""" - wrapped_name: str = '' - - if isinstance(property_, property): - wrapped_name = getattr(property_.fget, '__name__', '') - elif isinstance(property_, cached_property): # type: ignore - wrapped_name = getattr(property_.func, '__name__', '') # type: ignore - - return wrapped_name.startswith('_') and not wrapped_name.startswith('__') - - def computed_field( __f: PropertyT | None = None, *,