Giter Club home page Giter Club logo

Comments (4)

note35 avatar note35 commented on May 28, 2024 1

The one I followed previously is not the newest version.

I have not checked other missing function precisely, but I am pretty sure the newest Sinon.js changed and added lots APIs. Since I contributed part of new version's SinonJS document.

Feel free to list those new features you think can benefit this library, I am willing to extend current library :)

from sinon.

note35 avatar note35 commented on May 28, 2024
  • spyCall.calledOn # Returns true if obj was this for this call.

During the time I implement Sinon.py, I didn't implement any function related to scope this, because the concept of scope between Javascript is totally different from Python. (JavaScript is a functional programming language, however, Python is a OOP language.)

For example:
In JavaScript, there is closure concept => without bind(this):

Obj = {
    foo: function() {console.log("foo")},
    bar: function(runThisFunc) {runThisFunc()},
    baz: function() {
        this.bar(function() {
            this.foo()
        })
    }    
}
{foo: ƒ, bar: ƒ, baz: ƒ}
Obj.baz()

You will got this error.

Uncaught TypeError: this.foo is not a function

However, in Python

class Obj:                                                                                                         
    def foo(self):
        print("foo")
    def baz(self):
        def func(): self.foo()
        self.bar(func)
    def bar(self, run_this_func):
        run_this_func()

o = Obj()
o.baz()

It won't give any error.

Thus based on the difference between Python and JS, I didn't implement this feature.

from sinon.

jonathan-benn avatar jonathan-benn commented on May 28, 2024

Thus based on the difference between Python and JS, I didn't implement this feature.

That's a good point. Conversely, it makes sense to add some things to Sinon.PY, like kwargs. I will update the issue.

from sinon.

note35 avatar note35 commented on May 28, 2024

You are right, kwargs is a tricky thing in Python.

There are some part of my code need to be refactored about kwargs and args.

Because, for any function call of object, while it called by args, the first arguments will be object itself, later the arguments. On the other side, while it called by kwargs, the first arguments will be called argument.

For example:

class Obj(object):
   def func(a=0, b=0, c=0):
       pass
o = Obj()
o.func(1,2,3)
# args is (Obj, 1, 2, 3)
o.func(a=1, b=2, c=3)
# args is (Obj), kwargs is {'a': 1, 'b': 2, 'c': 3}

But, the above might meet some exception in some edge cases based on current implementation

I think there is a way to split args into 2 part, one for module/class, the other for pure args.

Also, this needs big efforts too, it impacts several places.

from sinon.

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.