我正在做一个项目,在这个项目中,我被要求使用责任链编写一些验证代码。我目前在我的机器上使用python 3.9.2,但是在docker上的项目是3.6.5
这段代码在我的机器上运行得很好,但是它破坏了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显示的错误如下:
from __future__ import annotations
django_1 | ^
django_1 | SyntaxError: future feature annotations is not defined有没有办法使代码在python3.6.5上工作?
发布于 2022-11-02 17:06:11
我在github上找到了这个答案,我正在重新发布,以防有人像我一样出现在这里。
正如@ForceBru annotations作为__future__的一部分是在Python中引入的,因此您需要手动添加dependency (或者将python版本向上移动,这是我推荐的)。
若要添加依赖项,请执行以下操作:
git clone -b legacy_py3.6 https://github.com/QUVA-Lab/e2cnn.git
cd e2cnn
python setup.py installhttps://stackoverflow.com/questions/66640159
复制相似问题