python / python/mypy

Spurious errors on the builtin open when running mypy on mypy

Open
#14,796 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

When running mypy following the procedure below, I encounter several errors for the overloaded open builtin of the form:

../python3.11/site-packages/mypy/typeshed/stdlib/builtins.pyi:1327: error: Argument 8 to "open" becomes "Optional[Any]" due to an unfollowed import  [no-any-unimported]

To reproduce:

  1. Set up a virtualenv with Python 3.11 and activate it.
  2. pip install mypy
  3. python-m mypy --strict --no-silence-site-packages --disallow-any-unimported -m mypy

Both --no-silence-site-packages and --disallow-any-unimported need to be present.

Version 1.0.0 of mypy is required. Older versions don't exhibit this error.

This is the simplest way we have found to reproduce this problem, but we first encountered it in one of our own projects.

The issue is being filed here because the mypy docs for reporting bugs says that problems with a specific library function should be reported here. We're not seeing this error with any other functions.

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.

Research direction

Reproduce the report with Python 3.11, mypy 1.0.0, and the documented command using --no-silence-site-packages and --disallow-any-unimported. Start by inspecting typeshed/stdlib/builtins.pyi around line 1327 and the handling of the builtin open; done means the command no longer reports the spurious no-any-unimported errors.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.