Skip to content

Fix .pyi stubs being shadowed by compiled modules in get_source_file#3099

Open
czinck wants to merge 2 commits into
pylint-dev:mainfrom
czinck:fix-3087-pyi-over-compiled
Open

Fix .pyi stubs being shadowed by compiled modules in get_source_file#3099
czinck wants to merge 2 commits into
pylint-dev:mainfrom
czinck:fix-3087-pyi-over-compiled

Conversation

@czinck

@czinck czinck commented Jun 11, 2026

Copy link
Copy Markdown

Type of Changes

Type
🐛 Bug fix

Description

#2722 generalized get_source_file from "if handed a .pyi, return it" to "if handed any non-source extension, return it as-is". Unfortunately, that also matched compiled bytecode (.pyc/.pyo) and binary extension modules (.so/.pyd/.dll): when import machinery handed in a .pyc that had a .pyi stub beside it, the .pyc was returned and then parsed as source, failing with "wrong encoding".

Exclude bytecode and binary-extension suffixes from that branch so they fall through to the normal stub/source lookup. The existing non-standard-extension behavior (custom suffixes like .weird_ext) is unchanged.

Closes #3087

czinck and others added 2 commits June 10, 2026 19:50
PR pylint-dev#2722 generalized ``get_source_file`` from "if handed a .pyi,
return it" to "if handed any non-source extension, return it as-is".
Unfortunately, that also matched compiled bytecode (.pyc/.pyo) and binary
extension modules (.so/.pyd/.dll): when import machinery handed in a
``.pyc`` that had a ``.pyi`` stub beside it, the ``.pyc`` was returned
and then parsed as source, failing with "wrong encoding".

Exclude bytecode and binary-extension suffixes from that branch so they
fall through to the normal stub/source lookup. The existing
non-standard-extension behavior (custom suffixes like ``.weird_ext``) is
unchanged.

Closes pylint-dev#3087
@codspeed-hq

codspeed-hq Bot commented Jun 14, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 3 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing czinck:fix-3087-pyi-over-compiled (2f4fa6d) with main (cf2db9b)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

@codecov

codecov Bot commented Jun 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.60%. Comparing base (cf2db9b) to head (2f4fa6d).
⚠️ Report is 16 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3099   +/-   ##
=======================================
  Coverage   93.60%   93.60%           
=======================================
  Files          92       92           
  Lines       11364    11367    +3     
=======================================
+ Hits        10637    10640    +3     
  Misses        727      727           
Flag Coverage Δ
linux 93.47% <100.00%> (+<0.01%) ⬆️
pypy 93.60% <100.00%> (+<0.01%) ⬆️
windows 93.57% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
astroid/modutils.py 89.49% <100.00%> (+0.11%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python stub (.pyi) files not recognized anymore

1 participant