[Python-Dev] Please reject or postpone PEP 526 (original) (raw)

Nick Coghlan ncoghlan at gmail.com
Mon Sep 5 10:02:08 EDT 2016


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, and perhaps as some form of Eiffel-style class invariant documentation syntax.

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

For ClassVar, you'd similarly want:

class AnnotatedClassVariable:

    x: ClassVar[int]

to typecheck like "x" was declared as an annotated property on the metaclass.

Cheers, Nick.

-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia



More information about the Python-Dev mailing list