Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions pydantic/_internal/_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ def __repr_args__(self) -> ReprArgs:
* name - value pairs, e.g.: `[('foo_name', 'foo'), ('bar_name', ['b', 'a', 'r'])]`
* or, just values, e.g.: `[(None, 'foo'), (None, ['b', 'a', 'r'])]`
"""
attrs_names = self.__slots__
if not attrs_names and hasattr(self, '__dict__'):
attrs_names = self.__dict__.keys()
attrs = ((s, getattr(self, s)) for s in attrs_names)
return [(a, v) for a, v in attrs if v is not None]
if not self.__slots__:
if hasattr(self, '__dict__'):
return [(k, v) for k, v in self.__dict__.items() if v is not None]
return []

return [(s, getattr(self, s)) for s in self.__slots__ if getattr(self, s) is not None]

def __repr_name__(self) -> str:
"""Name of the instance's class, used in __repr__."""
Expand Down
Loading