Skip to content

[BUG] NameError on self-referential class type annotations in matrix_exponentiation.py #15075

Description

@Kanika0306

Repository commit

15bcd92

Python version (python --version)

Python 3.11.7

Dependencies version (pip freeze)

N/A (Standard library only)

Expected behavior

Importing Python.maths.matrix_exponentiation should complete without error, allowing the Matrix class and type hints to be parsed cleanly:

import Python.maths.matrix_exponentiation


### Actual behavior


---

### **Actual behavior** *
```markdown
Importing `Python.maths.matrix_exponentiation` fails during module evaluation with a `NameError`:

```text
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "Python/maths/matrix_exponentiation.py", line 13, in <module>
    class Matrix:
  File "Python/maths/matrix_exponentiation.py", line 22, in Matrix
    def __mul__(self, b: Matrix) -> Matrix:
                         ^^^^^^
NameError: name 'Matrix' is not defined

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions