OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

When can mypy infer the type of containers such as collections.Counter?

  • Thread starter Thread starter Moberg
  • Start date Start date
M

Moberg

Guest
Running this mypy gist (https://mypy-play.net/?mypy=latest&python=3.12&gist=58a8148f2c95c7a282a6f8a11ccd689a)

Code:
from collections import Counter

C = Counter()

gives this mypy error:

Code:
main.py:3: error: Need type annotation for "C"  [var-annotated]
Found 1 error in 1 file (checked 1 source file)

Is there any way that mypy could infer this type?
<p>Running this mypy gist (<a href="https://mypy-play.net/?mypy=latest&python=3.12&gist=58a8148f2c95c7a282a6f8a11ccd689a" rel="nofollow noreferrer">https://mypy-play.net/?mypy=latest&python=3.12&gist=58a8148f2c95c7a282a6f8a11ccd689a</a>)</p>
<pre class="lang-py prettyprint-override"><code>from collections import Counter

C = Counter()
</code></pre>
<p>gives this mypy error:</p>
<pre class="lang-none prettyprint-override"><code>main.py:3: error: Need type annotation for "C" [var-annotated]
Found 1 error in 1 file (checked 1 source file)
</code></pre>
<p>Is there any way that mypy could infer this type?</p>
 

Latest posts

B
Replies
0
Views
1
Blundering Ecologist
B
Top