Hacker News new | ask | show | jobs
by GVRV 1622 days ago
This got me thinking and I'm not even seeing the `self` being returned in the list of parameters on Python 3.8.5:

   >>> class Test:
   ...     def test(self, a, b, c=5):
   ...         return a + b + c
   ...
   >>> t = Test()
   >>> inspect.signature(t.test).parameters
   mappingproxy(OrderedDict([('a', <Parameter "a">), ('b', <Parameter "b">), ('c', <Parameter "c=5">)]))
1 comments

That's because ``t.test`` returns a MethodType instance rather than a FunctionType instance, which is invoked without the self.
Ah, you're absolutely correct!

  In [4]: class Test:
     ...:     def test(self, a, b, c=5):
     ...:         return a + b + c
     ...:

  In [5]: inspect.signature(Test.test).parameters
  Out[5]:
  mappingproxy({'self': <Parameter "self">,
              'a': <Parameter "a">,
              'b': <Parameter "b">,
              'c': <Parameter "c=5">})
Then, any idea how you would address the GP's original point? How should "self" be detected if it can be called something else?