[Feature Request] evaluated_value() method on [static] containers
- Dominant language
- Python
- Stars
- 1.9k
- Forks
- 229
- PR merge metrics
- No merged PRs in 30d
Description
[Integer.evaluated_value](https://libcst.readthedocs.io/en/latest/nodes.html#libcst.Integer.evaluated_value) exists, so why not also a Tuple.evaluated_value, Dict.evaluated_value, etc?
Background:
I just cobbled together this mess of a function:
```python
def cst_literal_eval(node: cst.BaseExpression) -> Any:
ast_node = cst.Module([cst.SimpleStatementLine([cst.Expr(node)])]).code
try:
return ast.literal_eval(ast_node)
except Exception:
return None
```
In flake8-trio, for seeing if `for i in range(...)` can be statically determined to run at least once, and would be great to just be able to call `.evaluated_value` on the node directly.
(`.code` on something other than `Module` would also be neat, but that might be tricky).
Contributor guide
Assessment
This issue has not been assessed yet.