Discussion:
[issue19692] Rename Py_SAFE_DOWNCAST
Antoine Pitrou
2013-11-22 14:24:55 UTC
Permalink
New submission from Antoine Pitrou:

Py_SAFE_DOWNCAST's name is a bit misleading: it isn't safe except in debug mode. I propose to rename it to Py_DOWNCAST, so that developers are reminded that the burden of the sanity checks is on them.

----------
components: Interpreter Core
messages: 203764
nosy: christian.heimes, haypo, pitrou, tim.peters
priority: normal
severity: normal
status: open
title: Rename Py_SAFE_DOWNCAST
type: enhancement
versions: Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19692>
_______________________________________
Christian Heimes
2013-11-22 14:28:17 UTC
Permalink
Christian Heimes added the comment:

+1

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19692>
_______________________________________
STINNER Victor
2013-11-22 14:31:49 UTC
Permalink
STINNER Victor added the comment:

I like Py_DOWNCAST name.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19692>
_______________________________________
Antoine Pitrou
2013-11-22 15:15:47 UTC
Permalink
Antoine Pitrou added the comment:

Actually, _Py_DOWNCAST may be better (not a public API).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19692>
_______________________________________
Martin v. Löwis
2013-11-22 15:41:56 UTC
Permalink
Martin v. L?wis added the comment:

-1. The macro name doesn't claim the cast to be safe, i.e. it's not "Py_SAFELY_DOWNCAST", but "safe downcast", i.e. it's an assertion that the cast actually has been verified as being safe.

----------
nosy: +loewis

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19692>
_______________________________________
Antoine Pitrou
2013-11-22 15:45:04 UTC
Permalink
Post by Martin v. Löwis
-1. The macro name doesn't claim the cast to be safe, i.e. it's not
"Py_SAFELY_DOWNCAST", but "safe downcast", i.e. it's an assertion that
the cast actually has been verified as being safe.
It's not an assertion, it's a cast.
Otherwise it should be named Py_ASSERT_SAFE_DOWNCAST (and it should only
do the assertion, not the cast).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19692>
_______________________________________
Tim Peters
2013-11-22 15:51:18 UTC
Permalink
Tim Peters added the comment:

Goodness. Name it

_Py_DOWNCAST_AND_IN_DEBUG_MODE_ASSERT_UPCASTING_THE_RESULT_COMPARES_EQUAL_TO_THE_ORIGINAL_ARGUMENT

;-)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19692>
_______________________________________
Antoine Pitrou
2013-11-22 20:13:21 UTC
Permalink
Antoine Pitrou added the comment:

Well, I obviously won't fight very hard for this one.

But I would like to point out that APIs with "safe" (not "safely" :-)) in their name usually imply that the API is safe, not that the input has been sanitized beforehand.

For example in the stdlib: pprint.saferepr, string.safe_substitute, xmlrpc.client.SafeTransport. In the C API: Py_TRASHCAN_SAFE_BEGIN.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19692>
_______________________________________

Loading...