Skip to content

Commit

Permalink
Merge pull request #808 from azmeuk/issue-714-flag-repr
Browse files Browse the repository at this point in the history
display values in Flags repr
  • Loading branch information
azmeuk authored Oct 10, 2023
2 parents e205a99 + fef0952 commit 28514da
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
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

0 comments on commit 28514da

Please sign in to comment.