Giter Club home page Giter Club logo

Comments (5)

hgrecco avatar hgrecco commented on June 30, 2024

First, sorry for breaking things. The move to the new Formatter delegate allows more flexibility so I think this annoyance will pay off. Let me answer each of your questions:

Wouldn't a Unit object always be related to a registry, even if it's the default one ?
The formatter also format unit like objects (i.e. dicts mapping names to exponents) which do not necesesary require a registry.

Also, the way register_unit_format is written, wouldn't registry always be None
Yes. I was planning to try a solution but there was no need until now.

The idea would be to make this function look and instantiate the registered formatters.

    def get_formatter(self, spec: str):
        if spec == "":
            return self._formatters["D"]
        for k, v in self._formatters.items():
            if k in spec:
                return v

        try:
            orphan_fmt = REGISTERED_FORMATTERS[spec]
        except KeyError:
            return self._formatters["D"]

        try:
            fmt = orphan_fmt.__class__(self._registry)
            spec = get_attr(fmt, "spec", spec)
            self._formatters[spec] = fmt
            return fmt
        except:
            return orphan_fmt

from pint.

hgrecco avatar hgrecco commented on June 30, 2024

and then also add the spec attribute to NewFormatter here

from pint.

hgrecco avatar hgrecco commented on June 30, 2024

On a second thought
spec = get_attr(fmt, "spec", spec) and adding the spec attribut might not be necessary.

from pint.

aulemahal avatar aulemahal commented on June 30, 2024

I think I understand, thanks! I think I can try to suggest these changes in a PR if that helps.

from pint.

hgrecco avatar hgrecco commented on June 30, 2024

That would be great. I have review the code, it is necessary to add spec = get_attr(fmt, "spec", spec) and adding the spec attribute to NewFormatter. Let me know if you need help.

from pint.

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.