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

[feature request] A better repr for panflute AST #49

Open
ickc opened this issue Jan 13, 2017 · 2 comments
Open

[feature request] A better repr for panflute AST #49

ickc opened this issue Jan 13, 2017 · 2 comments
Labels
enhancement todo Stuff I want to update/fix/improve

Comments

@ickc
Copy link
Collaborator

ickc commented Jan 13, 2017

For example,

>>> from panflute import *
>>> table_referenced = Table(TableRow(TableCell(Plain(Str(''))), TableCell(Plain(Str('')))), TableRow(TableCell(Plain(Str('1'))), TableCell(Plain(Str('2')))), TableRow(TableCell(Plain(Str('3'))), TableCell(Plain(Str('4')))), alignment=['AlignDefault', 'AlignDefault'], width=[0.5, 0.5])
>>> repr(table_referenced)
"Table(TableRow(TableCell(Plain(Str())) TableCell(Plain(Str()))) TableRow(TableCell(Plain(Str(1))) TableCell(Plain(Str(2)))) TableRow(TableCell(Plain(Str(3))) TableCell(Plain(Str(4)))); alignment=['AlignDefault', 'AlignDefault'], width=[0.5, 0.5], rows=3, cols=2)"

It will be easier for writing tests if repr(table_referenced) would be just Table(TableRow(TableCell(Plain(Str(''))), TableCell(Plain(Str('')))), TableRow(TableCell(Plain(Str('1'))), TableCell(Plain(Str('2')))), TableRow(TableCell(Plain(Str('3'))), TableCell(Plain(Str('4')))), alignment=['AlignDefault', 'AlignDefault'], width=[0.5, 0.5]). i.e. if I copy the repr output and paste it, it would be a valid function to generate a panflute AST.

Currently, the __str__ points to the __repr__ method, may be the current repr will be moved to str, and has a new repr that has the said behavior?

@sergiocorreia
Copy link
Owner

Makes sense (also agrees with the stated purpose of repr).

That said, it might be a lot of work to have valid repr for most objects. Will try to see if I can push a quick commit but not entirely sure of the timeline.

@sergiocorreia
Copy link
Owner

Might also be a good idea to add more convenience functions/attributes, such as testing for equality, or adding a startswith method.

See https://github.com/bmc/ebook-template/blob/master/scripts/pandoc-filter.py for ideas

@sergiocorreia sergiocorreia added the todo Stuff I want to update/fix/improve label Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement todo Stuff I want to update/fix/improve
Projects
None yet
Development

No branches or pull requests

2 participants