Skip to content

Preserve builtin subclass types during call inference - #961

Open
2836048681 wants to merge 1 commit into
python-rope:masterfrom
2836048681:fix/828-infer-builtin-subclasses
Open

2836048681 wants to merge 1 commit into
python-rope:masterfrom
2836048681:fix/828-infer-builtin-subclasses

Conversation

@2836048681

Copy link
Copy Markdown

Instances of source-defined classes inheriting a builtin __new__ were inferred
as the builtin base type. For example, WordList() was inferred as a plain
list. Inlining WordList.extend could then delete its definition without
replacing words.extend(...), silently changing which implementation ran.

Use the source-defined class as the instance type when its __new__ is a builtin
function. Keep direct builtin construction and the inferred returns of
source-defined custom __new__ methods unchanged.

Add regressions for six builtin bases, indirect inheritance, custom constructors,
and inlining from either the method definition or its call. The inline regression
executes the result and checks that both elements are still Word instances.
Update the changelog.

Fixes #828.

Validation

Python 3.12.3, Linux:

  • Untouched-base suite, python -m pytest -q: 2176 passed, 11 skipped, 5 xfailed, 2001 warnings in 56.75s.
  • New tests against unchanged product code: 7 failures, with custom-constructor
    controls passing. Failures cover four builtin bases, indirect inheritance, and
    both inline selection locations. See screening/regressions-before.log.
  • Focused builtin/inline files, python -m pytest ropetest/builtinstest.py ropetest/refactor/inlinetest.py -q: 171 passed, 171 warnings, 8 subtests passed in 3.18s.
  • Full suite, python -m pytest -q --cov: 2181 passed, 11 skipped, 5 xfailed, 2004 warnings, 8 subtests passed in 224.07s (0:03:44).
  • Coverage report: TOTAL 26940 1271 95%.
  • The original issue's complete example executes with identical stdout before
    and after inlining, from both the definition and call site. Run
    ../.venv/bin/python ../screening/reproduce-828.py from the checkout.
  • All five configured pre-commit hooks pass for the changed files: trailing
    whitespace, final newline, large-file check, Black, and isort.
  • python -m pip check and git diff --cached --check pass.

The coverage run emits a warning about a temporary fixture source deleted during
teardown. Deprecation warnings remain; there are no test failures. Other Python
versions and operating systems were not run.

Checklist

  • Added tests that demonstrate the defect before the fix.
  • Updated CHANGELOG.md.
  • Ran the full suite and configured hooks locally.

This branch has not been deployed

No deployments
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.

The Inline Method removes an overridden method

2 participants