0

I get syntax error on code which I think has correct syntax.

from abc import ABC, abstractmethod
from typing import Any, Optional


class Handler(ABC):
    """
    The Handler interface declares a method for building the chain of handlers.
    It also declares a method for executing a request.
    """

    @abstractmethod
    def set_next(self, handler: Handler) -> Handler:
        pass

    @abstractmethod
    def handle(self, request) -> Optional[str]:
        pass

output from ipython:

Syntax error
File "/home/laci/git/python_playground/chain.py", line 12
   def set_next(self, handler: Handler) -> Handler:
Coolman
  • 166
  • 3
  • 11
  • Which version of Python? – jonrsharpe Jan 07 '20 at 12:14
  • Did you use an older Python version that does not support type annotations? – Klaus D. Jan 07 '20 at 12:15
  • Does this answer your question? [Type hints: solve circular dependency](https://stackoverflow.com/questions/33837918/type-hints-solve-circular-dependency) – carlosvin Jan 07 '20 at 13:02
  • python abstract class doesn't trigger the syntax error, it is circular dependency issue already described at https://stackoverflow.com/questions/33533148/how-do-i-specify-that-the-return-type-of-a-method-is-the-same-as-the-class-itsel – carlosvin Jan 07 '20 at 13:05

0 Answers0