MyPy complains if file replaced by shadow-file doesn't exist

Open
#4,746 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Start by reproducing the three commands in the issue with mypy 0.570 or a current checkout, then trace the --shadow-file argument handling and file-existence checks. Done means a missing source file mapped to an existing shadow file behaves like the shadow file, while an unrelated mapping does not produce a misleading missing-file error.

Written by the indexing model from the issue text.

Description

This is a follow-up to https://github.com/python/mypy/issues/2119. I think this a bug report, but maybe it's a feature request, or even possibly a documentation request.

I'm surprised by the following behavior of --shadow-file SOURCE_FILE SHADOW_FILE:

$ cd /tmp/
$ mkdir python
$ cd python/
$ echo "x = 1 + 'A'" > shadow.py
$ mypy --shadow-file error.py shadow.py error.py #1
mypy: can't read file 'error.py': No such file or directory
$ mypy --shadow-file error.py shadow.py shadow.py #2
mypy: can't read file 'shadow.py': No such file or directory
$ mypy shadow.py #3
shadow.py:1: error: Unsupported operand types for + ("int" and "str")

I see two problems here:

  • I expected # (1) to behave just as if there had been a file error.py with the contents of shadow.py, returning the same as # (3). This use case happens concretely when a user of Emacs creates a new file (but hasn't saved it to disk yet). In that case we create a temporary file with the contents of the unsaved file, and pass that as shadow.py, with error.py being the name of the yet-unsaved file.

  • In # (2) I did not expected the --shadow-file option to make a difference, since I remapped error.py to shadow.py and then asked about shadow.py (which shouldn't be affected by the unrelated mapping). Additionally, the error seems wrong (the file shadow.py exists).

I'm using mypy 0.570 and Python 3.5.2 (I have not tried with mypy from git master)

Am I misunderstanding the way --shadow-file is used?

Thanks!

Dominant language
Python
Stars
20.6k
Forks
3.3k
Avg merge
1d 18h
Merged PRs (30d)
54

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.

More from python/mypy

All issues in python/mypy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.