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

Joao S. O. Bueno jsbueno at python.org.br
Sun Feb 12 22:42:42 EST 2017


On 13 February 2017 at 00:55, Steven D'Aprano <steve at pearwood.info> wrote:
> On Sun, Feb 12, 2017 at 05:01:58PM -0200, Joao S. O. Bueno wrote:
>
>> 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.
>
> This is pure and unadulterated FUD.
>
> Nobody is going to use this as the standard way of writing classes. That
> would be silly: you end up repeating the class name over and over and
> over again.

Sorry - but the I just pointed the effect. The person saying
that would start writing classes this way is
the grand-parent poster:

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 are correct in your message, and thank you for calming me down,
 - but one thing remains: I was really scared by the grand parent poster -
and I still  prefer this possibility would not exist.

(And yes, I have code in which I needed doing what is proposed:
 the extra assignment line did not hurt me at all)


    js
  -><-
>
> And to say that this will happen "in a couple [of] months" is totally
> unrealistic. Although, I suppose that if the entire Python community did
> drop 2.7-3.6 and move to 3.7 within just one or two months so they could
> use this syntax, that would certainly vindicate the (hypothetical)
> decision to add this syntax.
>
> But honestly, no. This is not going to happen. .Net VB and C# have
> something like this, as does Lua, and people still write classes the
> ordinary way 99.99% of the time.
>
> The chances of this becoming the required, or even the recommended, way
> to write methods is much less than the chances of President Trump
> introducing Sharia law to the United States.
>
>
>> And all it will  take is some bureaucratic minded person to put that as default
>> option in some highly used linter, like the one that used-to-be-known-as-pep8.
>
> Do you *really* think that a linter that used to be called "PEP8" is
> going to require as a default syntax which (1) doesn't work before
> Python 3.7 at the earliest, and (2) has no support in PEP-8?
>
> It's one thing to question whether this feature is useful enough to be
> worth adding. It's another to make panicky claims that the Sky Will Fall
> if it is accepted.
>
>
> --
> Steve
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/


More information about the Python-ideas mailing list