]> granicus.if.org Git - python/commitdiff
inspect: Add some comments in Parameter.__eq__ method
authorYury Selivanov <yselivanov@sprymix.com>
Fri, 31 Jan 2014 20:30:30 +0000 (15:30 -0500)
committerYury Selivanov <yselivanov@sprymix.com>
Fri, 31 Jan 2014 20:30:30 +0000 (15:30 -0500)
Lib/inspect.py

index 48429652317ac2b56c5f1931a4e1bccdce5cd610..a65aafdb1b8f3bab4f949295ad7a661880558925 100644 (file)
@@ -1905,6 +1905,17 @@ class Parameter:
                                            id(self), self.name)
 
     def __eq__(self, other):
+        # NB: We deliberately do not compare '_partial_kwarg' attributes
+        # here. Imagine we have a following situation:
+        #
+        #    def foo(a, b=1): pass
+        #    def bar(a, b): pass
+        #    bar2 = functools.partial(bar, b=1)
+        #
+        # For the above scenario, signatures for `foo` and `bar2` should
+        # be equal.  '_partial_kwarg' attribute is an internal flag, to
+        # distinguish between keyword parameters with defaults and
+        # keyword parameters which got their defaults from functools.partial
         return (issubclass(other.__class__, Parameter) and
                 self._name == other._name and
                 self._kind == other._kind and