Code Monkey home page Code Monkey logo

Comments (2)

Suor avatar Suor commented on May 24, 2024

Given that decorator syntax is just a sugar one might go pre Python 2.4 way:

decorated = decorator(...)(func)

A more specific example can be found in this post (search for "retry"). Or in you case:

def load_file(path: str, retry_tries=None, retry_interval=0.075, unlink=False) -> t.IO[bytes]:
    """..."""
    if unlink:
        try:
            os.unlink(path)
        except:
            pass

    _open = open
    if retry_tries:
        logger.info(f"Retry loading file {path} for {retry_tries} times")
        _open = funcy.retry(tries=int(retry_tries), timeout=float(retry_interval))(open)
    return _open(path, "rb")

Not sure what non-decorator variant would help here, if it is something like:

_open = funcy.retry(open, tries=int(retry_tries), timeout=float(retry_interval))

Then it doesn't fill worth it for me. Actually being even a bit hurtful by providing an extra way to do the same with a non-significant consiseness gain. If you mean some sort of composition with partial for each of funcy's decorator then it also doesn't feel worth it - I would prefer things stay decomposed.

To the last on there is a tangentially related issue, the justification is the same here.

from funcy.

amotl avatar amotl commented on May 24, 2024

Dear Alexander,

thank you for sharing your excellent article Abstracting Control Flow.

Not sure what non-decorator variant would help here [...]. It doesn't fill worth it for me. Actually being even a bit hurtful by providing an extra way to do the same with a non-significant consiseness gain. If you mean some sort of composition with partial for each of funcy's decorator then it also doesn't feel worth it - I would prefer things stay decomposed.

I can completely follow your point here. Thanks a stack for your swift response.

Also, thank you very much for providing a more readable/structured variant of our load_file() function. I love it!

With kind regards,
Andreas.

from funcy.

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.