Skip to content

Commit

Permalink
Include conversion in FComponent.__repr__
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodiologist committed May 6, 2021
1 parent 78e84a3 commit 9098d74
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Bug Fixes
------------------------------
* REPL now properly displays SyntaxErrors.
* Fixed a bug in `pprint` in which `width` was ignored.
* Corrected `hy-repr` for f-strings.
* Corrected `repr` and `hy-repr` for f-strings.

.. _Toolz: https://toolz.readthedocs.io
.. _CyToolz: https://github.com/pytoolz/cytoolz
Expand Down
5 changes: 5 additions & 0 deletions hy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,11 @@ def replace(self, other, recursive=True):
self.conversion = other.conversion
return self

def __repr__(self):
return 'hy.models.FComponent({})'.format(
super(Object, self).__repr__() +
', conversion=' + repr(self.conversion))

class FString(Sequence):
"""
Generic Hy F-String object, for smarter f-string handling.
Expand Down
13 changes: 13 additions & 0 deletions tests/native_tests/language.hy
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,19 @@ cee\"} dee" "ey bee\ncee dee"))
f"{pi =:{fill =}^{width =}.2f}"))


(defn test-format-string-repr-roundtrip []
(for [orig [
'f"hello {(+ 1 1)} world"
'f"a{p !r:9}"
'f"{ foo = !s}"]]
(setv new (eval (repr orig)))
(assert (= (len new) (len orig)))
(for [[n o] (zip new orig)]
(when (hasattr o "conversion")
(assert (= n.conversion o.conversion)))
(assert (= n o)))))


(defn test-import-syntax []
"NATIVE: test the import syntax."

Expand Down

0 comments on commit 9098d74

Please sign in to comment.