On Mon, Nov 27, 2017 at 12:05 PM, Larry Hastings <la...@hastings.org> wrote: [..] > The PEP for > inspect.signature (PEP 362) says that when comparing two signatures for > equality, their positional and positional-or-keyword parameters must be in > the same order. It makes a point of *not* requiring that the two functions' > keyword-only parameters be in the same order.
Yes, and I believe Signature.__eq__ should stay that way. > > For every currently supported version of Python 3, inspect.signature and > fn.__code__.co_varnames preserve the order of keyword-only parameters. This > isn't surprising; it's basically the same code path implementing those as > the two types of positional-relevant parameters, so the most straightforward > implementation would naturally preserve their order. It's just not > guaranteed. > > I'd like inspect.signature to guarantee that the order of keyword-only > parameters always matches the order they were declared in. Technically this > isn't a language feature, it's a library feature. But making this guarantee > would require that CPython internally cooperate, so it's kind of a language > feature too. We can update the documentation and say that we preserve the order in simple cases: def foo(*, a=1, b=2): pass s = inspect.signature(foo) assert list(s.parameters.keys()) == ['a', 'b'] We can't say anything about the order if someone passes a partial object, or sets custom Signature objects to func.__signature__. Yury _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com