Skip to content

Commit cdb57a8

Browse files
Ignore files with name that starts like an emacs lock files (#5554)
* Fix 'path' shadowing variable from outer scope * Ignore file that starts like emacs's file lock Closes #367 Co-authored-by: Daniël van Noord <[email protected]>
1 parent 4f95e4d commit cdb57a8

12 files changed

+47
-7
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ Release date: TBA
3030

3131
Closes #5499
3232

33+
* By default, pylint does no longer take files starting with ``.#`` into account. Those are
34+
considered `emacs file locks`. See
35+
https://www.gnu.org/software/emacs/manual/html_node/elisp/File-Locks.html.
36+
This behavior can be reverted by redefining the ``ignore-patterns`` option.
37+
38+
Closes #367
39+
3340
* ``used-before-assignment`` now assumes that assignments in except blocks
3441
may not have occurred and warns accordingly.
3542

doc/whatsnew/2.13.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ Extensions
3232
Other Changes
3333
=============
3434

35+
* By default, pylint does no longer take files starting with ``.#`` into account. Those are
36+
considered `emacs file locks`_. This behavior can be reverted by redefining the
37+
``ignore-patterns`` option.
38+
39+
Closes #367
40+
41+
.. _`emacs file locks`: https://www.gnu.org/software/emacs/manual/html_node/elisp/File-Locks.html
42+
3543
* Fixed extremely long processing of long lines with comma's.
3644

3745
Closes #5483

pylint/lint/expand_modules.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99

1010
def _modpath_from_file(filename, is_namespace, path=None):
11-
def _is_package_cb(path, parts):
12-
return modutils.check_modpath_has_init(path, parts) or is_namespace
11+
def _is_package_cb(inner_path, parts):
12+
return modutils.check_modpath_has_init(inner_path, parts) or is_namespace
1313

1414
return modutils.modpath_from_file_with_callback(
1515
filename, path=path, is_package_cb=_is_package_cb

pylint/lint/pylinter.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,10 @@ def make_options():
223223
"type": "regexp_csv",
224224
"metavar": "<pattern>[,<pattern>...]",
225225
"dest": "black_list_re",
226-
"default": (),
226+
"default": (r"^\.#",),
227227
"help": "Files or directories matching the regex patterns are"
228-
" skipped. The regex matches against base names, not paths.",
228+
" skipped. The regex matches against base names, not paths. The default value "
229+
"ignores emacs file locks",
229230
},
230231
),
231232
(

pylint/testutils/configuration_test.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
import copy
66
import json
77
import logging
8+
import re
89
import unittest
910
from pathlib import Path
1011
from typing import Any, Dict, List, Tuple, Union
1112
from unittest.mock import Mock
1213

14+
from pylint.constants import PY38_PLUS
1315
from pylint.lint import Run
1416

1517
# We use Any in this typing because the configuration contains real objects and constants
@@ -18,6 +20,13 @@
1820
PylintConfiguration = Dict[str, ConfigurationValue]
1921

2022

23+
if not PY38_PLUS:
24+
# We need to deepcopy a compiled regex pattern
25+
# In python 3.6 and 3.7 this require a hack
26+
# See https://stackoverflow.com/a/56935186
27+
copy._deepcopy_dispatch[type(re.compile(""))] = lambda r, _: r # type: ignore[attr-defined]
28+
29+
2130
def get_expected_or_default(
2231
tested_configuration_file: Union[str, Path],
2332
suffix: str,
@@ -31,7 +40,7 @@ def get_expected_or_default(
3140
with open(expected_result_path, encoding="utf8") as f:
3241
expected = f.read()
3342
# logging is helpful to realize your file is not taken into
34-
# account after a misspell of the file name. The output of the
43+
# account after a misspelling of the file name. The output of the
3544
# program is checked during the test so printing messes with the result.
3645
logging.info("%s exists.", expected_result_path)
3746
else:
@@ -139,7 +148,7 @@ def run_using_a_configuration_file(
139148
# would not be accessible outside the `with` block.
140149
with unittest.mock.patch("sys.exit") as mocked_exit:
141150
# Do not actually run checks, that could be slow. We don't mock
142-
# `Pylinter.check`: it calls `Pylinter.initialize` which is
151+
# `PyLinter.check`: it calls `PyLinter.initialize` which is
143152
# needed to properly set up messages inclusion/exclusion
144153
# in `_msg_states`, used by `is_message_enabled`.
145154
check = "pylint.lint.pylinter.check_parallel"

pylint/utils/linterstats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def __str__(self) -> str:
155155
{self.percent_duplicated_lines}"""
156156

157157
def init_single_module(self, module_name: str) -> None:
158-
"""Use through Pylinter.set_current_module so Pyliner.current_name is consistent."""
158+
"""Use through PyLinter.set_current_module so PyLinter.current_name is consistent."""
159159
self.by_module[module_name] = ModuleStats(
160160
convention=0, error=0, fatal=0, info=0, refactor=0, statement=0, warning=0
161161
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# The name is invalid, but we should not analyse this file
2+
# Because its filename reseambles an emacs file lock ignored by default
3+
# https://www.gnu.org/software/emacs/manual/html_node/elisp/File-Locks.html
4+
# See https://github.com/PyCQA/pylint/issues/367
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# The name is invalid, but we should not analyse this file
2+
# Because it resembles an emacs file lock and is ignored by the configuration
3+
# See https://github.com/PyCQA/pylint/issues/367
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[MASTER]
2+
ignore-patterns=^\.#
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# [invalid-name]
2+
# The name is invalid and we should analyse this file
3+
# as ignore-patterns is redefined in the configuration

0 commit comments

Comments
 (0)