gpt4 book ai didi

python - flake8 e999 关于在 python2 中使用 fstrings(使用 future_fstrings)

转载 作者:太空宇宙 更新时间:2023-11-04 01:56:47 25 4
gpt4 key购买 nike

我在 pip install future-fstrings 之后在 python2 中使用 fstrings,如下所示:

# -*- coding: future_fstrings -*-
class A(object):
def __init__(self, **kw):
self.__dict__.update(**kw)
print (f'{self.a}')
print (f'{self.b}')
print (f'{self.c}')

A(a=1,b=2,c=3)

但是,当将这样的文件提交到我的项目时,我得到:

flake8 (Python 3.6 syntax check).....................(no files to check)Skipped
flake8 (Python 2.7)......................................................Failed
hookid: flake8

file_name:0:1: E999 SyntaxError: unknown encoding: future_fstrings

为什么会发生这种情况,我该如何解决?

#noqa E999 没有帮助...

最佳答案

预提交为每个钩子(Hook)创建隔离环境

您需要使该 linter 可以使用 future-fstrings:

    -   id: flake8
additional_dependencies: [future-fstrings]

完全披露:我是 pre-commit 和 future-fstrings 的作者,也是 flake8 的维护者,当它们都重叠时我很疯狂嘿

关于python - flake8 e999 关于在 python2 中使用 fstrings(使用 future_fstrings),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56629425/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com