[Python-ideas] Fwd: Define a method or function attributeoutsideof a class with the dot operator

Kyle Lahnakoski klahnakoski at mozilla.com
Mon Feb 13 13:25:00 EST 2017



On 2017-02-12 14:01, Joao S. O. Bueno wrote:
> On 12 February 2017 at 14:51, Markus Meskanen <markusmeskanen at gmail.com> wrote:
>> 1. Allowing the class to be used in the method's header, f.e. for typing and
>> decorators:
>>
>>   @decorate(MyClass)
>>   def MyClass.method(self, other: MyClass) -> List[MyClass]:
>>       ...
>>
>> This is useful since you can't refer the class itself inside of its body. At
>> the moment the way to use typing is to write the class's name as a string...
>> It feels awful.
> You realize now that if we accept this change, and given your example,
> any "well behaved" Python code with markup will in a  couple months
> required to be like
>
> class MyClass:
>       """Docstring."""
>
> def MyClass.__init__(self: MyClass, ...) -> None:
>      ...
>
> # add other methods here.

I am for method-outside-of-class form: If it is allowed, I will use it
extensively:

* instance methods and extension methods have the same form
* less lines between the line you are looking at and the name of the class
* explicit class name helps with searching for methods
* reduces indentation

thanks







More information about the Python-ideas mailing list