Use annotations on Pytnon 3.6.5

Viewed 2002

I'm working on a project where I was asked to code some validations using Chain of Responsibility. I am currently using python 3.9.2 on my machine, but the project on docker is on 3.6.5

This piece of code works nice on my machine, but it breaks on Docker:

from __future__ import annotations
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

The error that shows is the following:

 from __future__ import annotations
django_1    |     ^
django_1    | SyntaxError: future feature annotations is not defined

Is there a way to make the code work on python 3.6.5?

0 Answers
Related