On 23 September 2016 at 15:50, Greg Ewing <greg.ew...@canterbury.ac.nz> wrote:
> אלעזר wrote:
>>
>>     it feels like a
>>     placeholder for this meaning would be better.  E.g.:
>>
>>     class A:
>>         def __add__(self, other: CLS) -> CLS: ...
>
>
> That's fine for a class that refers to itself, but
> what about classes that refer to each other? This
> only addresses a small part of the problem.

Same answer as with any other circular dependency: the code smell is
the circular dependency itself, not the awkwardness of the syntax for
spelling it. If the string based "circular reference here!" spelling
really bothers you, refactor to eliminate the circularity (e.g. by
extracting a base class or an implementation independent interface
definition), rather than advocating to make the spelling less
obnoxious.

The difference between that and the "methods referring to the class
they're defined in" case is that it's likely to be pretty normal to
want to do the latter, so it may prove worthwhile to provide a cleaner
standard spelling for it. The counter-argument is the general
circularity one above: do you *really* need instances of the
particular class being defined? Or is there a more permissive
interface based type signature you could specify instead? Or perhaps
no type signature at all, and let ducktyping sort it out implicitly at
runtime?

Cheers,
Nick.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to