Coder Social home page Coder Social logo

Cython-Python pickling about multidict HOT 4 OPEN

aio-libs avatar aio-libs commented on September 26, 2024 1
Cython-Python pickling

from multidict.

Comments (4)

gyermolenko avatar gyermolenko commented on September 26, 2024

There are protocols 0..4 (inclusive). Maybe I could bump upper range in these places?
gen_pickles.py
conftest.py

ps after mentioned +1 number of tests turn from 36 to 44. And they pass

from multidict.

gyermolenko avatar gyermolenko commented on September 26, 2024

Regarding the issue itself..
Could you share some thoughts about desirable implementation?
Does it involve custom logic in __getnewargs__, __reduce__ and a bunch of other magic methods depending on USE_CYTHON variable?

from multidict.

asvetlov avatar asvetlov commented on September 26, 2024

My idea is to look on CPython sources.
Unfortunately, that's it for now

from multidict.

gyermolenko avatar gyermolenko commented on September 26, 2024

Here is what I got playing around with special methods related to pickle protocol:

import pickle

USE_CYTHON = True
# USE_CYTHON = False

class A:
    def __getnewargs_ex__(self):
        # print('in __getnewargs_ex__ of A')
        if USE_CYTHON:
            print('selecting path B')
            return ((B,), {})
        else:
            print('selecting path A')
            return ((A,), {})

    def __new__(cls, *args, **kwargs):
        # print('In A __new__, *args, **kwargs: ', *args, **kwargs)
        if args:
            return args[0]()
        else:
            return super().__new__(cls)

class B: pass

if __name__ == '__main__':
    obj = A()
    pd = pickle.dumps(obj)
    pl = pickle.loads(pd)
    #                           USE_CYTHON = True          USE_CYTHON = False
    print(pl.__class__)       # <class '__main__.B'>  or   <class '__main__.A'>

from multidict.

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.