Skip to content

Commit 914f0f9

Browse files
authored
Treat --python-version X.Y and --python-version=X.Y in tests equally (python#8026)
While working on python#8024 I noticed that `# flags: --python-version X.Y` and `# flags: --python-version=X.Y` are not treated equally by the test harness, namely the latter is actually ignored. This PR should fix this, because both forms are actually used in tests.
1 parent f9955ae commit 914f0f9

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

mypy/test/helpers.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ def parse_options(program_text: str, testcase: DataDrivenTestCase,
375375
if flags2:
376376
flags = flags2
377377

378-
flag_list = None
379378
if flags:
380379
flag_list = flags.group(1).split()
381380
flag_list.append('--no-site-packages') # the tests shouldn't need an installed Python
@@ -384,14 +383,14 @@ def parse_options(program_text: str, testcase: DataDrivenTestCase,
384383
# TODO: support specifying targets via the flags pragma
385384
raise RuntimeError('Specifying targets via the flags pragma is not supported.')
386385
else:
386+
flag_list = []
387387
options = Options()
388388
# TODO: Enable strict optional in test cases by default (requires *many* test case changes)
389389
options.strict_optional = False
390390
options.error_summary = False
391391

392-
# Allow custom python version to override testcase_pyversion
393-
if (not flag_list or
394-
all(flag not in flag_list for flag in ['--python-version', '-2', '--py2'])):
392+
# Allow custom python version to override testcase_pyversion.
393+
if all(flag.split('=')[0] not in ['--python-version', '-2', '--py2'] for flag in flag_list):
395394
options.python_version = testcase_pyversion(testcase.file, testcase.name)
396395

397396
if testcase.config.getoption('--mypy-verbose'):

test-data/unit/check-literal.test

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,12 @@ expr_com_3 = ... # type: Literal['3']
216216
expr_com_4 = ... # type: Literal['True']
217217
expr_com_5 = ... # type: Literal['None']
218218
expr_com_6 = ... # type: Literal['"foo"']
219-
reveal_type(expr_com_1) # N: Revealed type is 'Literal['a+b']'
220-
reveal_type(expr_com_2) # N: Revealed type is 'Literal['1+2']'
221-
reveal_type(expr_com_3) # N: Revealed type is 'Literal['3']'
222-
reveal_type(expr_com_4) # N: Revealed type is 'Literal['True']'
223-
reveal_type(expr_com_5) # N: Revealed type is 'Literal['None']'
224-
reveal_type(expr_com_6) # N: Revealed type is 'Literal['"foo"']'
219+
reveal_type(expr_com_1) # N: Revealed type is 'Literal[u'a+b']'
220+
reveal_type(expr_com_2) # N: Revealed type is 'Literal[u'1+2']'
221+
reveal_type(expr_com_3) # N: Revealed type is 'Literal[u'3']'
222+
reveal_type(expr_com_4) # N: Revealed type is 'Literal[u'True']'
223+
reveal_type(expr_com_5) # N: Revealed type is 'Literal[u'None']'
224+
reveal_type(expr_com_6) # N: Revealed type is 'Literal[u'"foo"']'
225225
[builtins fixtures/bool.pyi]
226226
[out]
227227

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy