compas icon indicating copy to clipboard operation
compas copied to clipboard

Use `__str__` to replaced `print_hierarchy`

Open Licini opened this issue 5 months ago • 6 comments

According to @chenkasirer there are some discussion about remove all print in core library, instead use __str__ for this type of functionalities. https://github.com/BlockResearchGroup/compas_model/pull/31#discussion_r1519911684

I made this change for Tree, let me know what you guys think.

What type of change is this?

  • [ ] Bug fix in a backwards-compatible manner.
  • [x] New feature in a backwards-compatible manner.
  • [x] Breaking change: bug fix or new feature that involve incompatible API changes.
  • [ ] Other (e.g. doc update, configuration, etc)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • [x] I added a line to the CHANGELOG.md file in the Unreleased section under the most fitting heading (e.g. Added, Changed, Removed).
  • [x] I ran all tests on my computer and it's all green (i.e. invoke test).
  • [x] I ran lint on my computer and there are no errors (i.e. invoke lint).
  • [ ] I added new functions/classes and made them available on a second-level import, e.g. compas.datastructures.Mesh.
  • [ ] I have added tests that prove my fix is effective or that my feature works.
  • [x] I have added necessary documentation (if appropriate)

Licini avatar Mar 28 '24 12:03 Licini

this looks great, but curious what's @tomvanmele @Licini take on str vs repr: could repr just invoke str?

jf--- avatar Apr 08 '24 12:04 jf---

the point of __repr__ is to allow for (re)construction of an object using eval of its string "repr"esentation. in the case of making something print-friendly we should use __str__ in my opinion. if i remember correctly, we only implement __repr__ if reconstruction is indeed possible...

tomvanmele avatar Apr 08 '24 17:04 tomvanmele

right, repr(oduction) its a neat feature, so repr can echo str when reconstruction isn't viable

jf--- avatar Apr 08 '24 18:04 jf---

@Licini sorry to ping, I'd just like to merge https://github.com/BlockResearchGroup/compas_model/pull/31 soon

chenkasirer avatar Apr 25 '24 13:04 chenkasirer

@Licini would indeed be good to finish this...

tomvanmele avatar Apr 25 '24 14:04 tomvanmele

@chenkasirer @gonzalocasas Sorry for late update on this folks. But now I can declare this is done 😂. If you guys give me a go I will merge now

Licini avatar Apr 29 '24 16:04 Licini