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

make json viewer more clear #2334

Closed
wants to merge 1 commit into from
Closed
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
20 changes: 15 additions & 5 deletions telebot/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,21 @@ def check_json(json_type, dict_copy = True):
raise ValueError("json_type should be a json dict or string.")

def __str__(self):
d = {
x: y.__dict__ if hasattr(y, '__dict__') else y
for x, y in self.__dict__.items()
}
return str(d)
return json.dumps(
self,
default=lambda obj: (
repr(obj) if not isinstance(obj, JsonDeserializable)
else {
attr: getattr(obj, attr)
for attr in filter(
lambda x: not x.startswith("_") and getattr(obj, x) is not None,
obj.__dict__
)
}
),
indent=2,
ensure_ascii=False
)


class Update(JsonDeserializable):
Expand Down
Loading