TensorType.shape is a mutable plain attribute

Open Beginner friendly
#2,330 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python

Research direction

Start by locating the Python definition of TensorType and compare its shape handling with XTensorType. Add or update the relevant test so assigning to shape raises AttributeError, then run that focused test to confirm the attribute is read-only.

Written by the indexing model from the issue text.

Description

Reproduction

import pytensor.tensor as pt
x = pt.scalar("x")
x.type.shape = (3,)

Expected behavior

shape should be a read-only property. Mutating it should raise AttributeError.

Actual behavior

shape is a plain instance attribute. Unlike XTensorType, TensorType has no derived attribute that goes out of sync when shape changes, so no observable corruption occurs. This is a consistency issue rather than a bug.

Environment

pytensor 3.2.4

Dominant language
Python
Stars
644
Forks
209
Avg merge
2d 14h
Merged PRs (30d)
16

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pymc-devs/pytensor

All issues in pymc-devs/pytensor

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.