Mypy: Self-referencing types

Created on 15 Sep 2014  路  2Comments  路  Source: python/mypy

There are some types that need to reference themselves. For instance:

class X():
    def some_func() -> X:
        ...

However, this is NOT valid Python 3 (X has not yet been fully declared at this point). Mypy should have a way for types to self-reference themselves (maybe a ThisType type?).

Most helpful comment

The current convention is to put it in quotes, e.g.

  class X:
      def some_func(self) -> 'X':
          ...

All 2 comments

The current convention is to put it in quotes, e.g.

  class X:
      def some_func(self) -> 'X':
          ...

@gvanrossum I wasn't aware of that. Whoops. Closing...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Stiivi picture Stiivi  路  3Comments

gregbedwell picture gregbedwell  路  3Comments

arquolo picture arquolo  路  3Comments

ambv picture ambv  路  3Comments

kissge picture kissge  路  3Comments