What is `ast.Tuple.dims` for?

What is ast.Tuple.dims for?
It exists in _ast.pyi:

...

class Tuple(expr):
    if sys.version_info >= (3, 10):
        __match_args__ = ("elts", "ctx")
    elts: list[expr]
    ctx: expr_context
    if sys.version_info >= (3, 9):
        dims: list[expr]

...

But I didn’t see any description about this attribute in docs.

“dims” was a deprecated field, removed in 3.9, replaced by “elts”, so that’s just for backwards compatibility.
See: https://github.com/python/cpython/blob/43a6e4fa4934fcc0cbd83f7f3dc1b23a5f79f24b/Lib/ast.py#L606

2 Likes

dims was an ExtSlice filed. After ExtSlice was merged with Tuple, dims was added as an alias of elts in Tuple, for limited backward compatibility.

Unless you need to support Python 3.8 and older, simply ignore ExtSlice and dims. ExtSlice() now returns a Tuple, and dims is an alias of elts. Both are deprecated and will be removed soon.

2 Likes