Skip to content

Fix builtin functions incorrectly exposing descriptor attributes#2983

Merged
DanielNoord merged 2 commits intopylint-dev:mainfrom
emmanuel-ferdman:fix-builtin-func-attrs
Mar 2, 2026
Merged

Fix builtin functions incorrectly exposing descriptor attributes#2983
DanielNoord merged 2 commits intopylint-dev:mainfrom
emmanuel-ferdman:fix-builtin-func-attrs

Conversation

@emmanuel-ferdman
Copy link
Copy Markdown
Contributor

Type of Changes

Type
🐛 Bug fix

Description

Builtin functions like eval, print, and len don't have __get__, __defaults__, __annotations__, etc. in Python - they're builtin_function_or_method, not regular functions. But astroid was returning values for these anyway since FunctionModel didn't distinguish between builtins and user-defined functions. This PR adds a check to raise AttributeInferenceError for these attributes on builtins, same as Python would raise AttributeError.

Closes #2743

Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.27%. Comparing base (6891ed0) to head (fb3fde5).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2983      +/-   ##
==========================================
- Coverage   93.30%   93.27%   -0.04%     
==========================================
  Files          92       92              
  Lines       11309    11341      +32     
==========================================
+ Hits        10552    10578      +26     
- Misses        757      763       +6     
Flag Coverage Δ
linux 93.13% <100.00%> (-0.04%) ⬇️
pypy 93.27% <100.00%> (-0.04%) ⬇️
windows 93.25% <100.00%> (-0.04%) ⬇️

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

Files with missing lines Coverage Δ
astroid/interpreter/objectmodel.py 96.08% <100.00%> (+0.13%) ⬆️

... and 1 file with indirect coverage changes

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

Copy link
Copy Markdown
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, looks good !

@DanielNoord DanielNoord merged commit 85226dd into pylint-dev:main Mar 2, 2026
19 of 27 checks passed
pylint-backport bot pushed a commit that referenced this pull request Mar 2, 2026
Fix builtin functions incorrectly exposing descriptor attributes

Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Co-authored-by: Daniël van Noord <13665637+DanielNoord@users.noreply.github.com>
(cherry picked from commit 85226dd)
DanielNoord added a commit that referenced this pull request Mar 2, 2026
Fix builtin functions incorrectly exposing descriptor attributes

Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Co-authored-by: Daniël van Noord <13665637+DanielNoord@users.noreply.github.com>
(cherry picked from commit 85226dd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

eval.__get__(1) should be an inference error

3 participants