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

[Lang] Define __str__ method for DataType #3370

Merged
merged 1 commit into from
Nov 4, 2021

Conversation

knight42
Copy link
Member

@knight42 knight42 commented Nov 3, 2021

Signed-off-by: knight42 anonymousknight96@gmail.com
fixes #3367

@netlify
Copy link

netlify bot commented Nov 3, 2021

✔️ Deploy Preview for jovial-fermat-aa59dc canceled.

🔨 Explore the source changes: f6d9f72

🔍 Inspect the deploy log: https://app.netlify.com/sites/jovial-fermat-aa59dc/deploys/6183503211ce1c00082e1847

@knight42
Copy link
Member Author

knight42 commented Nov 3, 2021

/cc @ailzhang

@knight42
Copy link
Member Author

knight42 commented Nov 4, 2021

/format

@@ -103,6 +103,7 @@ void export_lang(py::module &m) {
.def(py::self == py::self)
.def("__hash__", &DataType::hash)
.def("to_string", &DataType::to_string)
.def("__str__", &DataType::to_string)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need add __repr__ too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM!

Copy link
Contributor

@ailzhang ailzhang Nov 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__repr__ is more like for debugging purpose which includes object information.
I usually think in this way (maybe incorrect :P):
information from __str__ should be human readable (but can lose info)
But you can use information from __repr__ to reconstruct this object easily.
So IMHO only handling __str__ is good enough for now and we might consider adding __repr__ in the future :D

@knight42 knight42 changed the title feat: define __str__ method for DataType [Lang] feat: define __str__ method for DataType Nov 4, 2021
@knight42 knight42 changed the title [Lang] feat: define __str__ method for DataType [Lang] feat: define __str__ and __repr__ method for DataType Nov 4, 2021
@knight42 knight42 changed the title [Lang] feat: define __str__ and __repr__ method for DataType [Lang] Define __str__ and __repr__ method for DataType Nov 4, 2021
Copy link
Contributor

@ailzhang ailzhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice thanks!

@@ -103,6 +103,7 @@ void export_lang(py::module &m) {
.def(py::self == py::self)
.def("__hash__", &DataType::hash)
.def("to_string", &DataType::to_string)
.def("__str__", &DataType::to_string)
Copy link
Contributor

@ailzhang ailzhang Nov 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__repr__ is more like for debugging purpose which includes object information.
I usually think in this way (maybe incorrect :P):
information from __str__ should be human readable (but can lose info)
But you can use information from __repr__ to reconstruct this object easily.
So IMHO only handling __str__ is good enough for now and we might consider adding __repr__ in the future :D

Signed-off-by: knight42 <anonymousknight96@gmail.com>
@knight42 knight42 changed the title [Lang] Define __str__ and __repr__ method for DataType [Lang] Define __str__ method for DataType Nov 4, 2021
Copy link
Contributor

@ailzhang ailzhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!!

@yihong0618
Copy link
Collaborator

cool

@ailzhang ailzhang merged commit f5b8d11 into taichi-dev:master Nov 4, 2021
@knight42 knight42 deleted the feat-datatype-string branch November 4, 2021 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Properly support printing taichi data type string
3 participants