Skip to content

Commit

Permalink
Fix overload position of computed_field (#8227)
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Nov 27, 2023
1 parent 0c964d7 commit a6e1eba
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions pydantic/fields.py
Expand Up @@ -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')
Expand All @@ -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,
*,
Expand Down

0 comments on commit a6e1eba

Please sign in to comment.