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

display values in Flags repr #808

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Version 3.x.x

Unreleased

- Display :class:`~wtforms.Flags` values in their repr

Version 3.1.0
-------------

Expand Down
6 changes: 5 additions & 1 deletion src/wtforms/fields/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,11 @@ def __contains__(self, name):
return getattr(self, name)

def __repr__(self):
flags = (name for name in dir(self) if not name.startswith("_"))
flags = (
f"{name}={getattr(self, name)}"
for name in dir(self)
if not name.startswith("_")
)
return "<wtforms.fields.Flags: {%s}>" % ", ".join(flags)


Expand Down
2 changes: 1 addition & 1 deletion tests/fields/test_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_unset(flags):


def test_repr(flags):
assert repr(flags) == "<wtforms.fields.Flags: {required}>"
assert repr(flags) == "<wtforms.fields.Flags: {required=True}>"


def test_underscore_property(flags):
Expand Down
Loading