Hello,

Here's example:

Traceback (most recent call last):
  File "pseudoc_tool.py", line 91, in <module>
    first_class_function_value(func, **pass_params)
TypeError: print() got an unexpected keyword argument 'noann'


Ok, which "print" do you mean, dear CPython? I have a dozen of print
functions (mostly methods) around. So I now need to reduce to printf
debugging to find which one is actually meant. And what if that happens
in 3rd-party library installed in /usr/lib? On a production system?

The most interesting fact is that despite functions has always been
first-class values and 30-years language history, such issues are still
there.

I'm fixing this right away in my Pycopy dialect, because while it's
minimalist and I tremble over each half-byte added, but it's Python
first of all, and Python means good error reporting.

Well, actually I don't fix it right away, but work around, put putting
source loc in TypeError's error message. And here's an idea of what the
real fix should be:

The fact that CPython (and Pycopy) sets up function's frame "outside"
the function execution is an implementation detail. The model of
execution should be: there's a CALL_FUNCTION/CALL_FUNCTION_KW opcode,
and after it executes, the context switches to the target function, and
that's *when* argument checking happens. That would give the desired
behavior that the last entry in traceback is the actual function
which was called and which failed parameter checks.

Again, it's an implementation detail if some project doesn't do it like
that, and performs param checking before actually pointing VM at the
new bytecode function (from which location traceback will be
automatically constructed). If it does that, it just still need to
append an additional traceback entry pointing to the beginning of the
target function.

I now implemented that too, and now everything makes sense:

Traceback (most recent call last):
  File "pseudoc_tool.py", line 91, in <module>
  File "../xforms.py", line 25, in print
TypeError: unexpected keyword argument 'noann'


-- 
Best regards,
 Paul                          mailto:pmis...@gmail.com
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/VY3QAU2TEXOPELGDS7RTQOX4357QWILR/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to