On Sat, Oct 16, 2021 at 09:54:13AM +0100, Alex Waygood wrote:
> > On 16 Oct 2021, at 06:13, Steven D'Aprano <st...@pearwood.info> wrote:
> > Be careful about believing what you are told.
> 
> Indeed, MyPy will correctly raise errors if you assign {None: []} to a 
> variable annotated with dict[str, Number]. However, you'll find that 
> MyPy also raises an error if you assign {'foo': 4} to a variable 
> annotated with dict[str, Number]:

Hah, serves me right for not testing it for both positive and negative 
cases.

In my very limited testing now, I see that the problem appears to be 
with the Number type. mypy correctly accepts this:

    Data = Dict[str, int]
    a: Data = {'spam': 42}

(no errors), but if you change the annotation to use Number instead of 
int, it wrongly flags that as a type error.

Possibly mypy doesn't know that ints and floats are instances of Number?

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/FJY3QKAUJOJYTODMZH72X2ZS63GKT6AN/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to