Coder Social home page Coder Social logo

Comments (2)

huangy10 avatar huangy10 commented on August 10, 2024

原因其实不复杂,不过我也绕晕了一会儿,问题在于Python2和Python3中的types.MethodType的作用不一样了。在ipython中通过help来列出二者的用法,可以发现是不同的:

# Python 2
Help on class instancemethod in module __builtin__:

class instancemethod(object)
 |  instancemethod(function, instance, class)
 |
 |  Create an instance method object.

# Python 3
class method(object)
 |  method(function, instance)
 |
 |  Create a bound instance method object.

在Python2中,你可以把一个方法作为“实例方法”绑定到一个类的身上,并且之后从该类创建的实例的对应方法,都将是你所指定的这个方法。但是Python3中不同了,如果你将instance指定成一个类,那么Python3会将这个类视为一个实例,为其绑定一个bind方法,那么此时的bind实质上就成了这个类的类方法。所以你在new_bind函数中拿到的self就是类本身了(cls)。

解决这个问题很简单。我创建了一个新的PR,相信你一看就懂了。

from pysocket.

falseen avatar falseen commented on August 10, 2024

感谢!终于把这个问题给解决了。

from pysocket.

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.