balabit / typesafety

Type safety checker for Python3
GNU Lesser General Public License v2.1
23 stars 9 forks source link

Forward references #17

Open attilammagyar opened 9 years ago

attilammagyar commented 9 years ago

How about this?

  Scenario: forward references
    Given that "fwref.py" contains the following code:
          """
          class Myself:
              def equals(self, other: id) -> bool:
                  return other == self

          a = Myself()
          b = Myself()
          a.equals(b)
          a.equals(42)
          """
     When "python3 fwref.py" is run
     Then it must fail:
          """
          typesafety.validator.TypesafetyError: Argument 'other' of function 'equals' is invalid (expected: Myself; got: int)
          """

(Note that there's a different idea for this in PEP0484: https://www.python.org/dev/peps/pep-0484/#forward-references )