[issue37645] Replace PyEval_GetFuncName/PyEval_GetFuncDesc

2019-11-06 Thread Petr Viktorin


Petr Viktorin  added the comment:

With this change, CPython no longer uses PyEval_GetFuncName/PyEval_GetFuncDesc 
internally.
Shall we deprecate/discourage them?
Shall we expose PyObject_FunctionStr publicly?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37645] Replace PyEval_GetFuncName/PyEval_GetFuncDesc

2019-11-05 Thread miss-islington


miss-islington  added the comment:


New changeset bf17d41826a8bb4bc1e34ba6345da98aac779e41 by Miss Islington (bot) 
(Jeroen Demeyer) in branch 'master':
bpo-37645: add new function _PyObject_FunctionStr() (GH-14890)
https://github.com/python/cpython/commit/bf17d41826a8bb4bc1e34ba6345da98aac779e41


--
nosy: +miss-islington

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37645] Replace PyEval_GetFuncName/PyEval_GetFuncDesc

2019-10-31 Thread Ronan Lamy


Change by Ronan Lamy :


--
nosy: +Ronan.Lamy

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37645] Replace PyEval_GetFuncName/PyEval_GetFuncDesc

2019-09-11 Thread Petr Viktorin


Petr Viktorin  added the comment:

My bad, I didn't publish the comments. They should be there now.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37645] Replace PyEval_GetFuncName/PyEval_GetFuncDesc

2019-09-11 Thread Jeroen Demeyer


Jeroen Demeyer  added the comment:

> I left some comments on the PR.

I don't see anything. Either I'm doing something wrong or GitHub is messed up.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37645] Replace PyEval_GetFuncName/PyEval_GetFuncDesc

2019-09-11 Thread Petr Viktorin


Petr Viktorin  added the comment:

I like PR 14890 better. I like the separation of representation for error 
messages (where it's clearer that this is a callable) and for __str__.

Also, changing the __str__ of functions would need much wider discussion than 
on issues/PRs.

I left some comments on the PR.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37645] Replace PyEval_GetFuncName/PyEval_GetFuncDesc

2019-08-17 Thread Jeroen Demeyer


Jeroen Demeyer  added the comment:

> I'm wary of "%S" used in error messages.

Maybe you're misunderstanding something. The goal is not really to change error 
messages, only the way how they are produced. For example, we currently have

>>> def f(): pass
>>> f(**1)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: f() argument after ** must be a mapping, not int

This is about how the "f()" in the error message is produced. Currently, this 
uses PyEval_GetFuncName() and PyEval_GetFuncDesc(). For the reasons explained 
in this issue, I want to replace that.

I see two ways of doing this:

1. (PR 14890) Write a new function _PyObject_FunctionStr(func) which returns 
func.__qualname__ + "()" with a suitable fallback if there is no __qualname__ 
attribute. At some point, we could also introduce a %F format character for 
this.

2. (PR 15295) Use str(func) in the error message and change various __str__ 
methods (really tp_str functions) to give a more readable output.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37645] Replace PyEval_GetFuncName/PyEval_GetFuncDesc

2019-08-17 Thread Jeroen Demeyer


Jeroen Demeyer  added the comment:

> I'm wary of making error messages depend on the str representation of a 
> function; that would prevent us from changing it later.

Why wouldn't we be able to change anything? Typically, the exact string of an 
error message is NOT part of the API (the exception *type* is, but we're not 
talking about that).

> I'm wary of "%S" used in error messages. Those are for the programmer, not 
> the user

I'm not following here. Given that Python is a programming language, the user 
*is* the programmer.

Anyway, you don't have to be convinced. I'm trying to solve a problem here and 
I have two approaches (PR 14890 and PR 15295). I'm more inclined towards PR 
15295, but if you like the idea of PR 14890 better, we can go with that instead.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37645] Replace PyEval_GetFuncName/PyEval_GetFuncDesc

2019-08-15 Thread Petr Viktorin


Petr Viktorin  added the comment:

I am not convinced.

I'm wary of making error messages depend on the str representation of a 
function; that would prevent us from changing it later.
I'm wary of "%S" used in error messages. Those are for the programmer, not the 
user, so they should prefer __repr__.

I train beginners to recognize "" as a sign of 
omitted parentheses. The ugliness is useful: it shows you're dealing with an 
internal object, not a data value.

So, I think "" is much better than just "f()". I wouldn't mind 
"" (maybe even with the full signature), but that doesn't quite 
help this case.
(I don't care much for the "at 0x7f9f4bbe5e18" part, but that's not the issue 
here.)

--
nosy: +petr.viktorin

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37645] Replace PyEval_GetFuncName/PyEval_GetFuncDesc

2019-08-14 Thread Jeroen Demeyer


Change by Jeroen Demeyer :


--
pull_requests: +15018
pull_request: https://github.com/python/cpython/pull/15295

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37645] Replace PyEval_GetFuncName/PyEval_GetFuncDesc

2019-08-14 Thread Jeroen Demeyer


Jeroen Demeyer  added the comment:

> Maybe repr(func) should be left unchanged, but str(func) can be enhanced?

Yes, that is what I meant.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37645] Replace PyEval_GetFuncName/PyEval_GetFuncDesc

2019-08-14 Thread STINNER Victor


STINNER Victor  added the comment:

Maybe repr(func) should be left unchanged, but str(func) can be enhanced?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37645] Replace PyEval_GetFuncName/PyEval_GetFuncDesc

2019-08-04 Thread Jeroen Demeyer


Jeroen Demeyer  added the comment:

Another solution would be to change the __str__ of various function objects to 
a prettier output. For example, we currently have

>>> def f(): pass
>>> print(f)


We could change this to

>>> def f(): pass
>>> print(f)
f()

and then use "%S" to display the functions in error messages. But I have a 
feeling that this is a more controversial change than PR 14890.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37645] Replace PyEval_GetFuncName/PyEval_GetFuncDesc

2019-07-21 Thread Jeroen Demeyer


Change by Jeroen Demeyer :


--
keywords: +patch
pull_requests: +14673
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/14890

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37645] Replace PyEval_GetFuncName/PyEval_GetFuncDesc

2019-07-21 Thread Jeroen Demeyer


Jeroen Demeyer  added the comment:

4. It uses the __name__ instead of the __qualname__

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37645] Replace PyEval_GetFuncName/PyEval_GetFuncDesc

2019-07-21 Thread Jeroen Demeyer


New submission from Jeroen Demeyer :

PyEval_GetFuncName is bad API because

1. It hardcodes a limited number of function classes (which doesn't even 
include all function classes in the core interpreter) instead of supporting 
duck-typing.
2. In case of a "function" object, it relies on a borrowed reference to the 
function.
3. It is returning a C string instead of a Python string, so we cannot return a 
new reference even if we wanted to.

Since PyEval_GetFuncName and PyEval_GetFuncDesc are always used together, we 
might as well replace them by a single function with a proper API.

--
components: Interpreter Core
messages: 348255
nosy: jdemeyer, vstinner
priority: normal
severity: normal
status: open
title: Replace PyEval_GetFuncName/PyEval_GetFuncDesc
versions: Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com