Skip to content

Commit 2f6c087

Browse files
author
Aleksey Petryankin
committed
Preliminary changes 2
- Responses to review comments - Add test for calling _astroid_module_checker on different levels - Move Path.resolve() out of recursive calls
1 parent 04d878c commit 2f6c087

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

pylint/config/config_initialization.py

-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from pylint.lint import PyLinter
2424

2525

26-
# pylint: disable = too-many-statements
2726
def _config_initialization(
2827
linter: PyLinter,
2928
args_list: list[str],
@@ -144,10 +143,6 @@ def _config_initialization(
144143

145144
linter._parse_error_mode()
146145

147-
# Link the base Namespace object on the current directory
148-
if Path(".").resolve() not in linter._directory_namespaces:
149-
linter._directory_namespaces[Path(".").resolve()] = (linter.config, {})
150-
151146
# parsed_args_list should now only be a list of inputs to lint.
152147
# All other options have been removed from the list.
153148
return list(

pylint/config/find_default_config_files.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def _cfg_has_config(path: Path | str) -> bool:
6464
return any(section.startswith("pylint.") for section in parser.sections())
6565

6666

67-
def _yield_default_files(basedir: Path | str = ".") -> Iterator[Path]:
67+
def _yield_default_files(basedir: Path = Path(".")) -> Iterator[Path]:
6868
"""Iterate over the default config file names and see if they exist."""
6969
basedir = Path(basedir)
7070
for config_name in CONFIG_NAMES:
@@ -144,8 +144,3 @@ def find_default_config_files() -> Iterator[Path]:
144144
yield Path("/etc/pylintrc").resolve()
145145
except OSError:
146146
pass
147-
148-
149-
def find_subdirectory_config_files(basedir: Path | str) -> Iterator[Path]:
150-
"""Find config file in arbitrary subdirectory."""
151-
yield from _yield_default_files(basedir)

pylint/lint/pylinter.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ def set_current_module(self, modname: str, filepath: str | None = None) -> None:
927927
# If there is an actual filepath we might need to update the config attribute
928928
if filepath:
929929
config_path, namespace = self._get_namespace_for_file(
930-
Path(filepath), self._directory_namespaces
930+
Path(filepath).resolve(), self._directory_namespaces
931931
)
932932
if namespace:
933933
self.config = namespace
@@ -940,7 +940,6 @@ def set_current_module(self, modname: str, filepath: str | None = None) -> None:
940940
def _get_namespace_for_file(
941941
self, filepath: Path, namespaces: DirectoryNamespaceDict
942942
) -> tuple[Path | None, argparse.Namespace | None]:
943-
filepath = filepath.resolve()
944943
for directory in namespaces:
945944
if _is_relative_to(filepath, directory):
946945
_, namespace = self._get_namespace_for_file(

tests/lint/test_pylinter.py

+20
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
from unittest.mock import patch
1010

1111
from pytest import CaptureFixture
12+
from test_regr import REGR_DATA
1213

1314
from pylint.lint.pylinter import PyLinter
15+
from pylint.typing import FileItem
1416
from pylint.utils import FileState
1517

1618

@@ -48,3 +50,21 @@ def test_crash_during_linting(
4850
assert len(files) == 1
4951
assert "pylint-crash-20" in str(files[0])
5052
assert any(m.symbol == "astroid-error" for m in linter.reporter.messages)
53+
54+
55+
def test_global_vs_local_astroid_module() -> None:
56+
fileitems = iter(
57+
[
58+
FileItem("filename", __file__, "modname"),
59+
FileItem("name2", str(Path(REGR_DATA, "decimal_inference.py")), "mod2"),
60+
]
61+
)
62+
linter1 = PyLinter()
63+
ast_mapping = linter1._get_asts(fileitems, None)
64+
with linter1._astroid_module_checker() as check_astroid_module:
65+
linter1._lint_files(ast_mapping, check_astroid_module)
66+
stats1 = linter1.stats
67+
linter2 = PyLinter()
68+
linter2._lint_files(ast_mapping, None)
69+
stats2 = linter2.stats
70+
assert str(stats1) == str(stats2)

0 commit comments

Comments
 (0)