Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TYP: Suboptimally annotated arithmetic operator types #27965

Closed
@adamjstewart

Description

@adamjstewart

Describe the issue:

Arithmetic operators like division do not take shape typing into account, resulting in false-positive type hinting issues.

Originally reported here: #27957 (comment)
Some debugging work done by @jorenham at here: #27957 (comment)
Opening a separate bug report as requested

Reproduce the code example:

import numpy as np

x = np.zeros(1)
x = x / 1

Error message:

test.py:4: error: Incompatible types in assignment (expression has type "ndarray[tuple[int, ...], dtype[floating[Any]]]", variable has type "ndarray[tuple[int], dtype[float64]]")  [assignment]

Python and NumPy Versions:

2.2.0
3.13.0 (main, Nov 21 2024, 10:46:46) [Clang 16.0.0 (clang-1600.0.26.4)]

Type-checker version and settings:

mypy 1.11.2 (compiled: no)
mypy --strict

Additional typing packages.

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions