Home > other >  Generic type defaults to int?
Generic type defaults to int?

Time:03-03

I am trying the following example to learn the Generic typing in Python and can't figure out what is the default type for a Generic type.

An example from PEP 484 : enter image description here

What that example is trying to illustrate is that once the type checker knows that a has type MyClass[int] it does NOT accept calls to meth_1 or meth_2 with a str.

This is in contrast with the example directly preceding it on the original page where it IS still possible (to call meth_2 with a str).

  • Related