[Python-ideas] Optional static typing -- the crossroads

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Aug 16 02:26:09 CEST 2014


Łukasz Langa wrote:

> class C:
>   cls_member: str = ‘on the class’
> 
>   def __init__(self):
>     self.obj_member: str = ‘on the instance'
>     self.cls_member = 2   # that’s the real question: type error or an 
> instance member?

I think not treating it as an error would make it hard
to reason about the type of x.cls_member for an instance
x of C. Its type would depend on whether del x.cls_member
had been performed on x.

Code which relied on them being different types would
be rather confusing to a human reader too, so it's
probably fine to discourage that.

-- 
Greg


More information about the Python-ideas mailing list