fix: sync prqlc Python type stub with binding signatures#6058
Open
prql-bot wants to merge 1 commit into
Open
Conversation
The .pyi stub drifted from the actual PyO3 signatures since #4333: - rq_to_sql accepts an optional CompileOptions, but the stub declared only rq_to_sql(rq_json: str) - CompileOptions.__init__ accepts color and display kwargs, absent from the stub ty (run in CI via nox) checks user/test code against these stubs, so passing options to rq_to_sql or color/display to CompileOptions was flagged as a type error despite working at runtime. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Found during the nightly survey. The Python type stub
prqlc/bindings/prqlc-python/python/prqlc/__init__.pyihas drifted from the actual PyO3 binding signatures since #4333 ("Adddisplayoption tocompile, allow specifying colors"):rq_to_sqlaccepts an optionalCompileOptionsin the binding (pub fn rq_to_sql(rq_json: &str, options: Option<CompileOptions>)), but the stub declared onlyrq_to_sql(rq_json: str) -> str.CompileOptions.__init__acceptscoloranddisplaykeyword arguments (the PyO3#[new]signature is(*, format, signature_comment, target, color, display)), but the stub listed onlyformat,target,signature_comment.This repo runs
ty checkin CI (via thetypingnox session intest-python.yaml), which validates user and test code against these stubs. Soprqlc.rq_to_sql(rq, options)orprqlc.CompileOptions(color=..., display=...)— both valid at runtime — were flagged as type errors against the stale stub.Solution
Update the stub to match the binding:
rq_to_sql(rq_json: str, options: Optional[CompileOptions] = None) -> strcolor: bool = Falseanddisplay: str = "plain"toCompileOptions.__init__(keyword-only, ordered to match the Rust#[new]signature)Testing
Added
test_rq_to_sql_optionstotest_all.py, which callsrq_to_sqlwith aCompileOptions(constructed withcolor/display) and asserts the SQL output. This exercises the full public signatures, soty checkfails against the old stub and passes against the fixed one.Verified locally by building the wheel (
maturin build) and running the suite:ty checkreports 3 diagnostics (too-many-positional-argumentsonrq_to_sql, plus unexpected-kwarg errors onCompileOptions).pytest(4 passed) andty check("All checks passed!") are green.Note for maintainers
convert_optionsinprqlc/bindings/prqlc-python/src/lib.rscurrently hardcodescolor: false, ignoring thecolorfield the constructor accepts. This PR only surfaces the parameter in the stub to match the constructor — it doesn't change that behavior. Ifcoloris meant to be non-functional in the Python binding, dropping it from the constructor (rather than the stub) would be the alternative; that's a maintainer call, so I left the behavior untouched here.Found via the automated nightly code-quality survey.