Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5610a23

Browse files
authored
Provide a better fallback value for the python_version option (#19162)
Followup to#19157. After droppingsupport for an old Python version, mypy should assume the next oldestone instead of the current interpreter version.
1 parentdcd79c4 commit5610a23

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

‎mypy/config_parser.py‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
_INI_PARSER_CALLABLE:_TypeAlias=Callable[[Any],_CONFIG_VALUE_TYPES]
2929

3030

31+
classVersionTypeError(argparse.ArgumentTypeError):
32+
"""Provide a fallback value if the Python version is unsupported."""
33+
34+
def__init__(self,*args:Any,fallback:tuple[int,int])->None:
35+
self.fallback=fallback
36+
super().__init__(*args)
37+
38+
3139
defparse_version(v:str|float)->tuple[int,int]:
3240
m=re.match(r"\A(\d)\.(\d+)\Z",str(v))
3341
ifnotm:
@@ -44,7 +52,7 @@ def parse_version(v: str | float) -> tuple[int, int]:
4452
ifisinstance(v,float):
4553
msg+=". You may need to put quotes around your Python version"
4654

47-
raiseargparse.ArgumentTypeError(msg)
55+
raiseVersionTypeError(msg,fallback=defaults.PYTHON3_VERSION_MIN)
4856
else:
4957
raiseargparse.ArgumentTypeError(
5058
f"Python major version '{major}' out of range (must be 3)"
@@ -548,6 +556,9 @@ def parse_section(
548556
continue
549557
try:
550558
v=ct(section.get(key))
559+
exceptVersionTypeErroraserr_version:
560+
print(f"{prefix}{key}:{err_version}",file=stderr)
561+
v=err_version.fallback
551562
exceptargparse.ArgumentTypeErroraserr:
552563
print(f"{prefix}{key}:{err}",file=stderr)
553564
continue

‎test-data/unit/cmdline.test‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,20 @@ python_version = 3.9
440440
python_version = 3.14
441441
[out]
442442

443+
[case testPythonVersionFallback]
444+
# cmd: mypy main.py
445+
[file main.py]
446+
import sys
447+
if sys.version_info == (3, 9): # Update here when bumping the min Python version!
448+
reveal_type("good")
449+
[file mypy.ini]
450+
\[mypy]
451+
python_version = 3.8
452+
[out]
453+
mypy.ini: [mypy]: python_version: Python 3.8 is not supported (must be 3.9 or higher)
454+
main.py:3: note: Revealed type is "Literal['good']?"
455+
== Return code: 0
456+
443457
-- This should be a dumping ground for tests of plugins that are sensitive to
444458
-- typeshed changes.
445459
[case testTypeshedSensitivePlugins]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp