Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions pytest_mypy_plugins/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,6 @@ def prepare_mypy_cmd_options(self, execution_path: Path) -> List[str]:
if not self.disable_cache:
mypy_cmd_options.extend(["--cache-dir", self.incremental_cache_dir])

python_version = ".".join([str(part) for part in sys.version_info[:2]])
mypy_cmd_options.append(f"--python-version={python_version}")

# Merge `self.base_ini_fpath` and `self.additional_mypy_config`
# into one file and copy to the typechecking folder:
mypy_ini_config = ConfigParser()
Expand All @@ -324,6 +321,15 @@ def prepare_mypy_cmd_options(self, execution_path: Path) -> List[str]:
additional_config = "[mypy]\n" + additional_config
mypy_ini_config.read_string(additional_config)

# Default python_version to the executing version, but don't override value set
# in given ini file. If we have a valid configuration we set the value in the
# [mypy] section, otherwise we pass it as a CLI option.
python_version = ".".join([str(part) for part in sys.version_info[:2]])
if "mypy" in mypy_ini_config.sections():
mypy_ini_config["mypy"].setdefault("python_version", python_version)
else:
mypy_cmd_options.append(f"--python-version={python_version}")

if mypy_ini_config.sections():
mypy_config_file_path = execution_path / "mypy.ini"
with mypy_config_file_path.open("w") as f:
Expand Down