Skip to content

Guard against import machinery masking out attributes#171

Open
stefanv wants to merge 2 commits into
scientific-python:mainfrom
stefanv:guard-against-module-overwrite
Open

Guard against import machinery masking out attributes#171
stefanv wants to merge 2 commits into
scientific-python:mainfrom
stefanv:guard-against-module-overwrite

Conversation

@stefanv
Copy link
Copy Markdown
Member

@stefanv stefanv commented Jun 3, 2026

Thank you to @matthew-brett for uncovering and analyzing this issue.

This deals with the case where a function my_func is defined in my_func.py. In some cases where the my_func submodule is imported (e.g. from pkg.my_func import ..., import pkg.my_func, or import * accessing a sibling attribute in the same file) the import machinery updates the package __dict__ with the my_func (the submodule) overriding access to my_func (the function).

This wraps the package __setattr__ to intercept those (and only those) problematic assignments.

@stefanv stefanv added the type: Bug fix Something isn't working label Jun 3, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 3, 2026

Codecov Report

❌ Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.54%. Comparing base (af0adfc) to head (e788bb1).

Files with missing lines Patch % Lines
src/lazy_loader/__init__.py 76.92% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main     #171      +/-   ##
===========================================
- Coverage   100.00%   97.54%   -2.46%     
===========================================
  Files            1        1              
  Lines          109      122      +13     
  Branches        19       23       +4     
===========================================
+ Hits           109      119      +10     
- Misses           0        1       +1     
- Partials         0        2       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@stefanv stefanv requested a review from effigies June 3, 2026 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: Bug fix Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant