[Python-Dev] PEP 575: Unifying function/method classes
let me start by saying that I'm much in favour of this change. It cleans up
a lot of the function implementation and makes it much easier to integrate
efficiently with external wrapper tools.
Guido van Rossum schrieb am 14.04.2018 um 23:14:
> On Sat, Apr 14, 2018 at 2:17 AM, Jeroen Demeyer wrote:
>> On 2018-04-13 21:30, Raymond Hettinger wrote:
>>> It would be nice to have a section that specifically discusses the
>>> implications with respect to other existing function-like tooling:
>>> classmethod, staticmethod, partial, itemgetter, attrgetter, methodgetter,
>> My hope is that there are no such implications. An important design goal
>> of this PEP (which I believe I achieved) is that as long as you're doing
>> duck typing, you should be safe. I believe that the tools in your list do
>> exactly that.
>> It's only when you use inspect or when you do type checks that you will
>> see the difference with this PEP.
> That actually sounds like a pretty big problem. I'm sure there is lots of
> code that doesn't *just* duck-type nor calls inspect but uses isinstance()
> to decide how to extract the desired information.
After some discussion, it seems that we can avoid the backwards
incompatibility by going half of the way first. We can keep the existing
"builtin_function_or_method" type for now, and mostly just add the common
base function type at the top. That provides most of the benefits,
including fast integration with native external function implementations
and most of the cleanup, while not requiring changes to type tests in user
The final split could then be done later, e.g. for Py4.0, where people
would be less surprised about minor breakages. The problem is that this
change does not really fit into the deprecation cycle since there is no
specific use case to warn about. Most code will simply keep working, and
there is no specific code pattern that would break. It really depends on
the exact reasons why some piece of code (thinks it) needs to do a type
check. Such code is usually easy to fix, and also improve along the way,
probably even by reducing the type checking or by starting to use "inspect"
instead of direct (fragile) type checks. Much of the code that could
potentially break probably only exists to work around the quirks of the
current function types implementation in CPython, which this PEP
specifically aims to clean up.