Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ Release date: TBA

Closes #2684

* Fix bug where ``pylint code.custom_extension`` would analyze ``code.py`` or ``code.pyi`` instead if they existed.

Closes pylint-dev/pylint#3631


What's New in astroid 3.3.9?
============================
Release date: 2025-03-09
Expand Down
5 changes: 3 additions & 2 deletions astroid/modutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,9 @@ def get_source_file(
"""
filename = os.path.abspath(_path_from_filename(filename))
base, orig_ext = os.path.splitext(filename)
if orig_ext == ".pyi" and os.path.exists(f"{base}{orig_ext}"):
return f"{base}{orig_ext}"
orig_ext = orig_ext.lstrip(".")
if orig_ext not in PY_SOURCE_EXTS and os.path.exists(f"{base}.{orig_ext}"):
return f"{base}.{orig_ext}"
for ext in PY_SOURCE_EXTS_STUBS_FIRST if prefer_stubs else PY_SOURCE_EXTS:
source_path = f"{base}.{ext}"
if os.path.exists(source_path):
Expand Down
4 changes: 4 additions & 0 deletions script/.contributors_aliases.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"[email protected]": {
"mails": ["[email protected]"],
"name": "Charlie Ringström"
},
"[email protected]": {
"mails": ["[email protected]"],
"name": "correctmost"
Expand Down
16 changes: 16 additions & 0 deletions tests/test_modutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,22 @@ def test_pyi_preferred(self) -> None:
os.path.normpath(module) + "i",
)

def test_nonstandard_extension(self) -> None:
package = resources.find("pyi_data/find_test")
modules = [
os.path.join(package, "__init__.weird_ext"),
os.path.join(package, "standalone_file.weird_ext"),
]
for module in modules:
self.assertEqual(
modutils.get_source_file(module, prefer_stubs=True),
module,
)
self.assertEqual(
modutils.get_source_file(module),
module,
)


class IsStandardModuleTest(resources.SysPathSetup, unittest.TestCase):
"""
Expand Down
Empty file.
Empty file.