Feature or enhancement
Proposal:
suppose the following code
it produces such byte code
0 0 RESUME 0
1 2 LOAD_CONST 0 (1)
4 LOAD_CONST 1 ((1, 2))
6 CONTAINS_OP 0
8 RETURN_VALUE
however, interpreter can easily fold such an expression to a constant in the ast_opt stage. This only applies if both ast nodes are Constant_kind. But there is one obstacle. Types are not yet ready and have incomplete mro at the ast_opt stage. So we can't use functions like PyObject_RichCompare for this. We can compare pointers to PyObject instead, since we know that each object in a "constant expression" is internally a singleton (interned strings, integers from -5 to 255, etc.). Thus, for them, the == operator is semantically equal to the is operator. I'm going to make pull request for this
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs
Feature or enhancement
Proposal:
suppose the following code
it produces such byte code
however, interpreter can easily fold such an expression to a constant in the ast_opt stage. This only applies if both ast nodes are
Constant_kind. But there is one obstacle. Types are not yet ready and have incomplete mro at the ast_opt stage. So we can't use functions likePyObject_RichComparefor this. We can compare pointers to PyObject instead, since we know that each object in a "constant expression" is internally a singleton (interned strings, integers from -5 to 255, etc.). Thus, for them, the==operator is semantically equal to theisoperator. I'm going to make pull request for thisHas this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs