Skip to content

Preserve positional-only and keyword-only parameter bindings - #898

Open
yangfan-yf-yf wants to merge 1 commit into
python-rope:masterfrom
yangfan-yf-yf:fix/function-parameter-kinds
Open

yangfan-yf-yf wants to merge 1 commit into
python-rope:masterfrom
yangfan-yf-yf:fix/function-parameter-kinds

Conversation

@yangfan-yf-yf

Copy link
Copy Markdown
Contributor

I found that positional-only and keyword-only parameters can resolve to an outer assignment instead of their own binding. Inlining target = 42 above def func(*, target): return target generates the invalid declaration def func(*, 42). Inlining only the body reference leaves valid code that returns 42 instead of the int passed by func(target=int). Rename and argument inference also lose the parameter identity or use the wrong argument slot.

I now give each parameter a stable binding slot, distinguish positional and keyword matching, and evaluate defaults in the enclosing scope. The ordinary slots are positional-only, positional-or-keyword, and keyword-only parameters; variadic object slots follow them. A keyword with the same name as a positional-only parameter goes to **kwargs without replacing the positional slot. Unknown unpacking and unknown supplied values do not invent default bindings.

I also align static analysis, dynamic call records, method receivers, and callable-object receivers with that layout. A receiver is inserted once: static methods receive none, class methods retain the actual dispatch class, and variadic receivers do not occupy keyword-only slots. Versioned, persistable call scopes isolate changed layouts and receiver rules from old records, including fallback reads; ordinary plain-function and per-name records retain their existing scopes. Static-method parameter attributes are kept separate from the containing class, including actual builtin decorator aliases.

Read-only completion and calltips use the parameter metadata while preserving ordinary signature display. Signature-writing refactorings reject unsupported positional-only or keyword-only rewrites before generating changes. Existing positional-only Inline Method behavior is preserved; keyword-only Inline Method remains unsupported. This change covers parameter bindings and defaults; general annotation-expression scope and deferred-evaluation inlining remain separate boundaries.

Validation:

  • 113 new regression cases exercise public refactoring APIs, identity, real program execution, argument inference, dynamic records, persistence, and compatible or rejected signature consumers.
  • Core 64 cases pass on Python 3.12 and 3.14; the latest 17-case increment has 15 failures and 2 passing controls on unchanged master. Earlier baseline increments are retained with their original test hashes.
  • Python 3.12 full suite: 2262 passed, 12 skipped, 5 xfailed. Local product patch coverage is 334/343 executable added lines, 97.38%; the remaining uncovered lines are recorded separately.
  • Python 3.14 full suite: 2266 passed, 8 skipped, 5 xfailed.
  • All five repository style hooks pass on the 21 changed files. Both new test files also pass explicit formatting/import checks, and git diff --check passes. Product, test, and documentation hashes are unchanged across the final runs and checks.

@codecov

codecov Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.06152% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.47%. Comparing base (22f5e50) to head (7733d55).

Files with missing lines Patch % Lines
rope/contrib/codeassist.py 95.52% 3 Missing ⚠️
rope/base/pyobjects.py 50.00% 2 Missing ⚠️
rope/base/oi/objectinfo.py 98.27% 1 Missing ⚠️
rope/refactor/functionutils.py 92.30% 1 Missing ⚠️
rope/refactor/inline.py 94.73% 1 Missing ⚠️
ropetest/parameter_kinds_test.py 99.79% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #898      +/-   ##
==========================================
+ Coverage   95.34%   95.47%   +0.12%     
==========================================
  Files         134      136       +2     
  Lines       26762    27667     +905     
==========================================
+ Hits        25516    26414     +898     
- Misses       1246     1253       +7     

☔ View full report in Codecov by Harness.
📢 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.

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.

1 participant