Repository navigation
Enforce Clinic binding by default #9563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
be64a6a
efe1fea
0323f43
dd25d16
13fccd2
9bb75fc
ba505df
a5d2485
fc193e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -421,20 +421,9 @@ impl Constructor for PyStr { | |||||||||||||||||||
| type Args = StrArgs; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| fn slot_new(cls: PyTypeRef, func_args: FuncArgs, vm: &VirtualMachine) -> PyResult { | ||||||||||||||||||||
| // A call with keyword arguments is parsed by unicode_new, which counts | ||||||||||||||||||||
| // every argument. | ||||||||||||||||||||
| if !func_args.kwargs.is_empty() { | ||||||||||||||||||||
| let total = func_args.args.len() + func_args.kwargs.len(); | ||||||||||||||||||||
| if total > 3 { | ||||||||||||||||||||
| let keyword = if func_args.args.is_empty() { | ||||||||||||||||||||
| "keyword " | ||||||||||||||||||||
| } else { | ||||||||||||||||||||
| "" | ||||||||||||||||||||
| }; | ||||||||||||||||||||
| return Err(vm.new_type_error(format!( | ||||||||||||||||||||
| "str() takes at most 3 {keyword}arguments ({total} given)" | ||||||||||||||||||||
| ))); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| // Preserve the keyword-free str_vectorcall arity diagnostic. | ||||||||||||||||||||
| if func_args.kwargs.is_empty() && func_args.args.len() > 3 { | ||||||||||||||||||||
| return Err(vm.new_arity_type_error(Self::NAME, 0..=3, func_args.args.len())); | ||||||||||||||||||||
|
Comment on lines
+424
to
+426
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Limit the CPython uses 🐛 Proposed fix
Committable suggestion
|
||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Optimization: return exact str as-is (only when no encoding/errors provided) | ||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Limit the
long_vectorcallarity diagnostic to exactint.CPython sets
long_vectorcallonly as thetp_vectorcallofPyLong_Type. A heap subclass does not inherit it, so a call such asclass I(int): pass; I(1, 2, 3)goes throughlong_new. That path uses the Clinic_PyArg_UnpackKeywordsparser, which reportsint() takes at most 2 arguments (3 given).This new check runs for every
clsexceptbool. A subclass call therefore reportsint expected at most 2 arguments, got 3. Without this check, the binder would return the Clinic message for subclasses.Add a
cls.is(vm.ctx.types.int_type)guard so that only the exact type gets the vectorcall diagnostic.🐛 Proposed fix
Committable suggestion