Skip to content

Improve generated Python constructor diagnostics - #230

Merged
leileizhang (lei9444) merged 1 commit into
mainfrom
lei9444-python-constructor-diagnostics
Oct 30, 2026
Merged

leileizhang (lei9444) merged 1 commit into
mainfrom
lei9444-python-constructor-diagnostics

Conversation

@lei9444

Copy link
Copy Markdown
Contributor

Summary

Generated Python runtime-class constructor mismatches now report the supplied positional argument types and keyword names/types, followed by all distinct candidate signatures. Candidate names and types reuse the existing constructor stub formatter; parameter values and internal module names are not printed.

The change runs only after existing constructor dispatch has failed. Argument binding, conversions, overload ordering, native activation errors, successful calls, .pyi output, named factories, and inspect.signature() are unchanged. No runtime helper or eager cross-module import is added.

Reproduction

Generate a fresh Windows SDK Python package using the matching native runtime:

dynwinrt-codegen generate --namespace Windows.Foundation --class-name Uri --lang py --output generated_uri
from dynwinrt import RoApartment
from generated_uri.windows.foundation import Uri

with RoApartment():
    Uri(url="https://example.com")  # Wrong keyword; use uri=.
    # Separately try Uri(42) for a type mismatch, or Uri() for missing arguments.

Before, both the wrong-keyword and wrong-type calls raise only TypeError: No matching constructor for Uri.

After:

TypeError: No matching constructor for Uri(url=str). Expected one of: Uri(uri: str); Uri(base_uri: str, relative_uri: str)
TypeError: No matching constructor for Uri(int). Expected one of: Uri(uri: str); Uri(base_uri: str, relative_uri: str)

Validation

  • 9 constructor unit tests, 17 constructor/boundary/interface-dispatch/identity integration tests, and all 6 snapshot tests pass; Rust formatting passes.
  • Built the native wheel and baseline codegen from main aa3c43a1dc24108547e2e4cce0c995601be2af38 in isolated outputs. Ran the same real-WinRT positive/negative cases on baseline and updated generated packages with that runtime.
  • Native coverage includes positional, keyword, mixed and reordered keywords, both Uri overloads, default DataWriter construction, interface-compatible streams, subclasses, raw native wrapping, invalid keyword/count/type/range/duplicate inputs, and unchanged native OSError propagation. Diagnostics do not call argument repr, custom metaclass name hooks, or keyword formatting hooks.
  • Compared all 112 generated Python/stub files: only six runtime-class constructor failure paths differ; all 57 .pyi files are identical. JavaScript snapshots are unchanged.
  • Added the real generated-package regression to the existing Python native CI job with the matching runtime required.

Report supplied argument types and all projected constructor signatures on overload mismatch without changing dispatch or accepted calls.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

Mixed-language test coverage

Workflow status: ✅ Passed

Layer Lines Functions Branches/regions
Rust, including native .pyd/.node 86.68% 82.16% 86.3% regions
Python aggregate 70.79% n/a 38.22% branches
Python runtime 98.28% n/a 95% branches
Generated Python WinRT projections 68.65% n/a 30.46% branches
Generated Python WinRT implementations 72% n/a 46.3% branches
JavaScript aggregate 18.38% 24.85% 55.94% branches
JavaScript runtime 41.73% 41.53% 78.33% branches
Generated WinRT projections 17.27% 19.36% 52.51% branches
Generated WinRT implementations 45.99% 59.19% 60.97% branches
Generated Classic COM projections 11.38% 23.88% 53.1% branches

View workflow run and download full HTML/LCOV/XML reports

@lei9444
leileizhang (lei9444) merged commit 1111825 into main Oct 30, 2026
33 checks passed
@lei9444
leileizhang (lei9444) deleted the lei9444-python-constructor-diagnostics branch October 30, 2026 04:55
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.

2 participants