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

Aperta
#4,893 3 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
numpy, python
Ambito
devtools

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Merge medio
1g 18h
PR unite (30g)
54

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python/mypy

Tutte le issue di python/mypy

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.