Skip to content

Conversation

@BobTheBuidler
Copy link
Contributor

@BobTheBuidler BobTheBuidler commented Jul 30, 2025

This is WIP, I just needed the runners to run. This PR strives to accomplish all of the following:

We should be able to constant fold an expression like (str, int) for use cases such as isinstance(obj, (str, int)) . Currently, the tuple is constructed each time. It should be feasible to do this with any tuple comprised of literals, builtin types, and/or final values of any kind.

It should also be possible to "constant fold" a LOC such as:

requests.get(some_url, headers={"k0": "v0", "k1": "v1"})

We can't simply create a dictionary constant since dicts are mutable and we don't know what's going to happen in the called function, but we can hold a template dict in memory and PyDict_Copy it when it's time for use. This skips the hashing and any resizing during construction, and simply takes the hash table from the existing dict instead, which will be (possibly much) quicker than constructing from scratch each time.

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