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

Fix overload position of computed_field #8227

Merged
merged 1 commit into from Nov 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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