[Python-ideas] PEP proposal: unifying function/method classes
Antoine Pitrou
solipsis at pitrou.net
Fri Mar 23 06:25:54 EDT 2018
On Fri, 23 Mar 2018 07:25:33 +0100
Jeroen Demeyer <J.Demeyer at UGent.be> wrote:
> On 2018-03-23 00:36, Antoine Pitrou wrote:
> > It does make sense, since the proposal sounds ambitious (and perhaps
> > impossible without breaking compatibility).
>
> Well, *some* breakage of backwards compatibility will be unavoidable.
>
>
> My plan (just a plan for now!) is to preserve backwards compatibility in
> the following ways:
>
> * Existing Python attributes of functions/methods should continue to
> exist and behave the same
>
> * The inspect module should give the same results as now (by changing
> the implementation of some of the functions in inspect to match the new
> classes)
>
> * Everything from the documented Python/C API.
>
>
> This means that I might break compatibility in the following ways:
>
> * Changing the classes of functions/methods (this is the whole point of
> this PEP). So anything involving isinstance() checks might break.
>
> * The undocumented parts of the Python/C API, in particular the C structure.
One breaking change would be to add __get__ to C functions. This means
e.g. the following:
class MyClass:
my_open = open
would make my_open a MyClass method, therefore you would need to spell
it:
class MyClass:
my_open = staticmethod(open)
... if you wanted MyClass().my_open('some file') to continue to work.
Of course that might be considered a minor annoyance.
Regards
Antoine.
More information about the Python-ideas
mailing list