Ad
  • Custom User Avatar

    PS: that means this case is out of the scope of the kata, btw, if obj is the instance and not the class itself. But your code shouldn't raise in any case.

  • Custom User Avatar

    all methods are assigned directly to the class, and not to instances, now. So your code shouldn't actually raise an error for this specific case, afaik.

  • Default User Avatar

    I've been trying for a week or so to resolve this, I'm getting close but I cannot pass all the random tests - I always fail 10 - 20 tests depending on the number: Passed: 668 Failed: 17 Exit Code: 1
    All of them fail for the same reason: <function Meta.make_interceptor.._wrapped at 0x7fe3069021f0> should equal 'grtisp'

    I know Monadius pointed out that: Examples in the description show that new methods are assigned to instances, but the tests never do this: Methods are assigned to classes -> can you confirm this ?
    For example, my code will raise an AttributeError for this:

    obj.foo = lambda self,a,b,c,d,e: '5 params function'
    print(obj.foo(1,2,3,4,5))

    Maybe it's not that and my code simply cannot handle some corner case, but can you give me a hint at least ? Because it's getting really frustrating...

  • Custom User Avatar

    That test checks whether object methods can access the implicitely passed variable (normally called self). Note this should work, whether the variable is called self or something else. Looking at your code, I think you are having trouble with that second part.

    As an example, this code should work:

    class A:
        val = 5
        def get_v(self):
            return self.val
        def double_v(me):
            return me.val*2
    the_ob = A()
    print(the_ob.get_v()) # 5
    print(the_ob.double_v()) # 10
    
  • Default User Avatar

    My code fails at the following test: Methods can access 'self' var, even when not named 'self'.

    Traceback (most recent call last):
    File "/workspace/default/src/codewars-test/codewars_test/test_framework.py", line 111, in wrapper
    func()
    File "tests.py", line 212, in access_test
    test.assert_equals(the_ob.self_access('World'), 'World2')

    I'm not sure what else to verify...can you be more specific about the test case?