3

我在这段代码上收到 pep8 标记错误。(见下文)。

urlpatterns = patterns('',
                      (r'', include(v1_api.urls)),
                       url(
                       r"^ajax/photos/upload/(?P<slug>[-_\w]+)/$",
                       "medicms.views.upload_photos",
                       name="upload_photos"
                      ),
                       url(
                       r"^ajax/photos/recent/$",
                       "medicms.views.recent_photos",
                       name="recent_photos"
                      ),
                      )

我正在使用 jenkins 来修复 lint 和 pep8 错误。我需要将所有代码行减少到 79 个字符以下。这些行低于 79,但詹金斯在第 3 行说 127 > 79,在第 4 行说 106 > 79。

看起来我有缩进错误,詹金斯正在阅读两行代码,而它应该在其中读取一行。谁能看到我没有发现的任何明显错误?或者有谁知道这是否是詹金斯的一个已知问题?谢谢

4

1 回答 1

5

I don't find any errors; I can only guess that jenkins is incorrect. Running pep8 does produce 3 times the warning E124 closing bracket does not match visual indentation, which is probably also why jenkins complains here.

For this particular case (Django URL patterns), I tend to align things as follows:

urlpatterns = patterns(
    '',
    (r'', include(v1_api.urls)),
    url(
        r"^ajax/photos/upload/(?P<slug>[-_\w]+)/$",
        "medicms.views.upload_photos",
        name="upload_photos"
    ),
    url(
        r"^ajax/photos/recent/$",
        "medicms.views.recent_photos",
        name="recent_photos"
    ),
)

which at least shuts up pep8, and makes for shorter lines overall.

于 2013-06-14T12:08:51.190 回答