2

我在 python2 中使用 fstrings,pip install future-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没有帮助...

4

1 回答 1

2

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

您需要为该 linter 提供 future-fstrings :

    -   id: flake8
        additional_dependencies: [future-fstrings]

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

于 2019-10-05T00:39:47.283 回答