Fix magic "self" parameter detection.

Original code behaviour:
>>> def foo(self, a=None):
...    return 'works'
...
>>> context.foo(a=1)
works
>>> def foo(self, a):
...   return 'works'
...
>>> context.foo(1)
works
>>> context.foo(a=1)
TypeError: foo() takes exactly 2 non-keyword arguments (0 given)

New behaviour fixes this TypeError, to be closer to normal python
behaviour.
Also, original code was doing expensive checks before cheap ones.