Skip to content

Commit

Permalink
Refactor __repr__ method in TinyDB class for clarity and consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
marcfreir committed Nov 16, 2024
1 parent 10644a0 commit 9e6d74e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions tinydb/database.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This module contains the main component of TinyDB: the database.
"""

from typing import Dict, Iterator, Set, Type

from . import JSONStorage
Expand Down Expand Up @@ -76,7 +77,7 @@ class TinyDB(TableBase):
#: The name of the default table
#:
#: .. versionadded:: 4.0
default_table_name = '_default'
default_table_name = "_default"

#: The class that will be used by default to create storage instances
#:
Expand All @@ -88,7 +89,7 @@ def __init__(self, *args, **kwargs) -> None:
Create a new instance of TinyDB.
"""

storage = kwargs.pop('storage', self.default_storage_class)
storage = kwargs.pop("storage", self.default_storage_class)

# Prepare the storage
self._storage: Storage = storage(*args, **kwargs)
Expand All @@ -97,16 +98,15 @@ def __init__(self, *args, **kwargs) -> None:
self._tables: Dict[str, Table] = {}

def __repr__(self):

args = [
'tables={}'.format(list(self.tables())),
'tables_count={}'.format(len(self.tables())),
'default_table_documents_count={}'.format(self.__len__()),
'all_tables_documents_count={}'.format(
['{}={}'.format(table, len(self.table(table)))
for table in self.tables()]),
f"tables={list(self.tables())}",
f"tables_count={len(self.tables())}",
f"default_table_documents_count={self.__len__()}",
f'all_tables_documents_count={[f"{table}={len(self.table(table))}" for table in self.tables()]}',
]

return '<{} {}>'.format(type(self).__name__, ', '.join(args))
return "<{} {}>".format(type(self).__name__, ", ".join(args))

def table(self, name: str, **kwargs) -> Table:
"""
Expand Down

0 comments on commit 9e6d74e

Please sign in to comment.