Running with --disallow-any-expr errors on exprs from "unfollowed code" even with immediate cast / assignment.

Open
#4,893 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
numpy, python
Domain
devtools

Research direction

Reproduce the report using the command mypy --disallow-any-expr and the example in scratch_6.py, then compare the observed diagnostics with the linked command-line documentation. Trace how expressions from unfollowed imports are handled in the cast and annotated-assignment cases; done means both forms no longer produce the reported errors when their result is explicitly typed.

Written by the indexing model from the issue text.

Description

feature needs discussion topic-disallow-any topic-usability

Run mypy 0.580 on the following code with the flag:

mypy --disallow-any-expr

from typing import cast

import numpy as np # type: ignore

class C: ...

a = cast(C, np.array([1,2,3]))
b: C = np.array([1,2,3])

This yields the errors:

scratch_6.py:7: error: Expression has type "Any"
scratch_6.py:8: error: Expression has type "Any"

One each for the cast and assignment forms.

According to the docs on --disallow-any-expr (http://mypy.readthedocs.io/en/latest/command_line.html). I believe both the cast and the assignment to a typed variable should resolve the errors.

Note that I'm using numpy as my "unfollowed import" here, but the problem seems to occur with other "unfollowed" libraries I've tried as well. Substitute as convenient.

Dominant language
Python
Stars
20.6k
Forks
3.3k
Avg merge
1d 18h
Merged PRs (30d)
54

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 python/mypy

All issues in python/mypy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.