[Python-checkins] cpython: inspect: Add some comments in Parameter.__eq__ method

yury.selivanov python-checkins at python.org
Fri Jan 31 21:31:33 CET 2014


http://hg.python.org/cpython/rev/c7233921b612
changeset:   88868:c7233921b612
user:        Yury Selivanov <yselivanov at sprymix.com>
date:        Fri Jan 31 15:30:30 2014 -0500
summary:
  inspect: Add some comments in Parameter.__eq__ method

files:
  Lib/inspect.py |  11 +++++++++++
  1 files changed, 11 insertions(+), 0 deletions(-)


diff --git a/Lib/inspect.py b/Lib/inspect.py
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -1905,6 +1905,17 @@
                                            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

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list