Giter Club home page Giter Club logo

Comments (1)

gilch avatar gilch commented on September 27, 2024

The simplest approach would be to factor out the pickle into a constant. That would allow monkeypatching to work on the hissp package alone without rewriting the whole method. You still have to patch two places though.

The most correct might be to factor it out into a ContextVar, which might be the closest thing the Python standard library has to dynamic vars. It's arguably not a monkeypatch at that point. But do we really need that? Would we ever want to use dill and pickle in the same session? Maybe, Hissp is not necessarily run where it is compiled. I don't think this buys us much over a constant though. If you need that degree of control, unittest.mock.patch can swap the context for you as long as you're not threading or doing async shenanigans.

The above is arguably still a monkeypatch because it still needs the pickle global to be replaced. Ideally, that would read from the same ContextVar instead, but that would be a bit awkward in any place the compiler is using pickle, which brings us to the third option: infer the import name pickle from the .__name__ attr of the pickle module. This arguably fixes a DRY violation, where the same bit of information is stored in another place, although one too minor to normally bother with considering its greater overhead. However, this would make the first attach line all you need to monkeypatch to enable dill. Let's go with that for now.

from hissp.

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.