[Python-Dev] Please reject or postpone PEP 526
Koos Zevenhoven
k7hoven at gmail.com
Mon Sep 5 10:24:15 EDT 2016
On Mon, Sep 5, 2016 at 5:02 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On 5 September 2016 at 23:46, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> Under such "parameter annotation like" semantics, uninitialised
>> variable annotations would only make sense as a new form of
>> post-initialisation assertion,
Why not discuss this in the python-ideas thread where I quote myself
from last Friday regarding the notion of annotations as assertions?
>> and perhaps as some form of
>> Eiffel-style class invariant documentation syntax.
I hope this is simpler than it sounds :-)
> Thinking further about the latter half of that comment, I realised
> that the PEP 484 equivalence I'd like to see for variable annotations
> in a class body is how they would relate to a property definition
> using the existing PEP 484 syntax.
>
> For example, consider:
>
> class AnnotatedProperty:
>
> @property
> def x(self) -> int:
> ...
>
> @x.setter
> def x(self, value: int) -> None:
> ...
>
> @x.deleter
> def x(self) -> None:
> ...
>
> It would be rather surprising if that typechecked differently from:
>
> class AnnotatedVariable:
>
> x: int
>
How about just using the latter way? That's much clearer. I doubt this
needs a change in the PEP.
> For ClassVar, you'd similarly want:
>
>
> class AnnotatedClassVariable:
>
> x: ClassVar[int]
>
> to typecheck like "x" was declared as an annotated property on the metaclass.
>
Sure, there are many things that one may consider equivalent. I doubt
you'll be able to list them all in a way that everyone agrees on. And
I hope you don't take this as a challenge -- I'm in the don't-panic
camp :).
-- Koos
> Cheers,
> Nick.
>
> --
> Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
--
+ Koos Zevenhoven + http://twitter.com/k7hoven +
More information about the Python-Dev
mailing list