Code Monkey home page Code Monkey logo

Comments (6)

jaimergp avatar jaimergp commented on July 23, 2024 1

I was wondering whether other projects rely on this mixin idea or not, and yep, it's common! Great, I didn't think of this possibility.

Some examples:

We could also use reprlib, which I have just discovered. Man, the standard library is vast. From the docs:

The reprlib module provides a means for producing object representations with limits on the size of the resulting strings. This is used in the Python debugger and may be useful in other contexts as well.

from openff-evaluator.

SimonBoothroyd avatar SimonBoothroyd commented on July 23, 2024 1

This will be automatically handled once #226 is closed as pydantic provides this for free by default.

from openff-evaluator.

SimonBoothroyd avatar SimonBoothroyd commented on July 23, 2024

Thanks for the fantastic feedback!

Because I've always developed, ran and stepped through all of my code and examples directly in an IDE (currently PyCharm) I've never really used the str and repr representations because the debugger gives a full object hierarchy - so this need and use for them is great to know about!

Absolutely a PR would be most welcome to fix up the many instances I've missed! I wonder if we could just use a simple mix-in with an implementation similar to your ComputeResourcesRepr to automate this cleanly in the bulk of cases (at least, those that implement __getstate__ which should be most)?

from openff-evaluator.

jaimergp avatar jaimergp commented on July 23, 2024

I wonder if we could just use a simple mix-in with an implementation similar to your ComputeResourcesRepr to automate this cleanly in the bulk of cases?

Given that .__getstate__() is implemented the same way across all involved instances (returns a dict with string-representable keys and values), I'd say that yes, a Representable class only implementing __str__ and __repr__ for mixins would be enough. It could even check for the existence of __getstate__ and throw a warning otherwise, maybe?

edit: The mixin would have to define abstract methods for required definitions in the children classes.

from openff-evaluator.

SimonBoothroyd avatar SimonBoothroyd commented on July 23, 2024

I was wondering whether other projects rely on this mixin idea or not, and yep, it's common! Great, I didn't think of this possibility.

Some examples:

We could also use reprlib, which I have just discovered. Man, the standard library is vast. From the docs:

The reprlib module provides a means for producing object representations with limits on the size of the resulting strings. This is used in the Python debugger and may be useful in other contexts as well.

That's good to hear! And it sounds like this should be pretty simple to add in which is great!

from openff-evaluator.

jaimergp avatar jaimergp commented on July 23, 2024

I have just found about __qualname__, which might be what we need here instead of manually concatenating __module__, __class__.__name__ etc.

from openff-evaluator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.