I don't understand why that would work and this clearly doesn't? Mutual2 = "Mutual2" # Pre-declare Mutual2
class Mutual1: def spam(self, x=Mutual2): print(type(x)) class Mutual2: def spam(self): pass Mutual1().spam() prints class "str" rather than "type". On Tue, Sep 27, 2016 at 6:20 AM Stephen J. Turnbull < turnbull.stephen...@u.tsukuba.ac.jp> wrote: > Neil Girdhar writes: > > > I agree that circularity should in general be avoided, but it's not > always > > possible or elegant to do that. Sometimes you really need two classes > to > > refer to each other. In that case, why not expose your placeholder > idea to > > the user via a library? > > Why not just expose it through a simple assignment? > > https://mail.python.org/pipermail/python-ideas/2016-September/042563.html > > Note that this also works for typechecking in PEP 484 checkers that > allow forward reference via the stringified class name. See also > https://mail.python.org/pipermail/python-ideas/2016-September/042544.html, > which would allow eliding the assignment, but pollutes the class namespace. > > "Simple is better than complex." > > This feature is still looking for a persuasive use that needs it, and > not something simpler. > > Steve >
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/