Skip to content

[BUG] mypy errors due to missing value/variance via views #527

@alexander-held

Description

@alexander-held

Describe the bug

When using .view() to access bin values / variances (as described in #421 (comment)), mypy flags this code with an error in boost-histogram 1.0.0.

An example is below:

test.py:

import boost_histogram as bh

h = bh.Histogram(bh.axis.Variable([0, 10]), storage=bh.storage.Weight())
h.fill([1,2,3])
h.view().value
h.view().variance

Output from mypy:

test.py:5: error: Item "ndarray" of "Union[ndarray, View]" has no attribute "value"  [union-attr]
    h.view().value
    ^
test.py:5: error: Item "View" of "Union[ndarray, View]" has no attribute "value"  [union-attr]
    h.view().value
    ^
test.py:6: error: Item "ndarray" of "Union[ndarray, View]" has no attribute "variance"  [union-attr]
    h.view().variance
    ^
test.py:6: error: Item "View" of "Union[ndarray, View]" has no attribute "variance"  [union-attr]
    h.view().variance
    ^
Found 4 errors in 1 file (checked 1 source file)

This may not be a bug and instead the result of improper usage. In this case, is there another way to access this information directly?

Steps to reproduce
see above, using mypy==0.812, boost-histogram==1.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions