-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Failed assert(defcount <= code->co_argcount)
with sneaky __defaults__
replacement
#117050
Comments
Originally discovered during discussion of #117045 (comment). |
Note that to test this, |
What's the meaning to have a |
Eh, yeah. Maybe we should just say "we can't possibly support all of the weird code objects you can possibly create, so this isn't really a bug". This one just feels "different" since it only breaks when specializing. |
Yeah, you can easily crash the interpreter if you do weird stuff to the code object outer.__code__ = outer.__code__.replace(co_consts=tuple()) That's just something that you need to be responsible for - I don't think it's feasible for CPython to avoid crashing in any arbitrary case when the user can basically construct their code objects freely. |
Actually, I believe there is a difference. Yes, using This bug falls into the latter category and needs to be fixed. IMO just deleting the offending PS. Critical function attributes are: |
But this is not assignment to critical attributes. You can't repro this by assigning value to You can easily replace the co_consts = outer.__code__.co_consts[:-1] + ([None, None],) and trigger another assert:
I don't see a difference between the mechnism - once you change |
Yeah. Using code.replace() you can create arbitrary nonsense. Using only critical function attribute assignment you should not be. The example at the top of this issue is the only known instance of the latter. |
Sorry which example? The example Brandt gave in this issue uses |
Oh, that's true. There may be a variant that just requires assignment to |
In |
Mark wants to keep the assert, so let’s close the issue. |
Crash report
It's possible to fail an assert on debug builds by cleverly constructing function objects with the same version, but different numbers of defaults.
Example:
I think this is just an incorrect assert, but I'm not 100% sure. Haven't tested on earlier versions, but I suspect that 3.12 (and maybe even 3.11) fails here too.
This may be a good first issue for someone trying to dip their toes in the call specializations.
The text was updated successfully, but these errors were encountered: