Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 48ae9d5

Browse files
authored
Remove some python2 left-overs (#13340)
1 parent 17fd374 commit 48ae9d5

7 files changed

Lines changed: 12 additions & 33 deletions

File tree

misc/dump-ast.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,14 @@ def main() -> None:
2828
parser = argparse.ArgumentParser(
2929
description="Parse source files and print the abstract syntax tree (AST)."
3030
)
31-
parser.add_argument("--py2", action="store_true", help="parse FILEs as Python 2")
3231
parser.add_argument("--quiet", action="store_true", help="do not print AST")
3332
parser.add_argument("FILE", nargs="*", help="files to parse")
3433
args = parser.parse_args()
3534

36-
if args.py2:
37-
pyversion = defaults.PYTHON2_VERSION
38-
else:
39-
pyversion = defaults.PYTHON3_VERSION
40-
4135
status = 0
4236
for fname in args.FILE:
4337
try:
44-
dump(fname, pyversion, args.quiet)
38+
dump(fname, defaults.PYTHON3_VERSION, args.quiet)
4539
except CompileError as e:
4640
for msg in e.messages:
4741
sys.stderr.write("%s\n" % msg)

mypy/dmypy_server.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,6 @@ def filter_out_missing_top_level_packages(
10221022
+ search_paths.package_path
10231023
+ search_paths.typeshed_path
10241024
)
1025-
paths += tuple(os.path.join(p, "@python2") for p in search_paths.typeshed_path)
10261025
for p in paths:
10271026
try:
10281027
entries = fscache.listdir(p)
@@ -1038,8 +1037,6 @@ def filter_out_missing_top_level_packages(
10381037
elif entry.endswith("-stubs"):
10391038
# Possible PEP 561 stub package
10401039
entry = entry[:-6]
1041-
if entry.endswith("-python2"):
1042-
entry = entry[:-8]
10431040
if entry in packages:
10441041
found.add(entry)
10451042
return found

mypy/test/helpers.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,6 @@ def testfile_pyversion(path: str) -> Tuple[int, int]:
286286
return defaults.PYTHON3_VERSION
287287

288288

289-
def testcase_pyversion(path: str, testcase_name: str) -> Tuple[int, int]:
290-
if testcase_name.endswith("python2"):
291-
raise ValueError(testcase_name)
292-
return defaults.PYTHON2_VERSION
293-
else:
294-
return testfile_pyversion(path)
295-
296-
297289
def normalize_error_messages(messages: List[str]) -> List[str]:
298290
"""Translate an array of error messages to use / as path separator."""
299291

@@ -384,9 +376,9 @@ def parse_options(
384376
options.strict_optional = False
385377
options.error_summary = False
386378

387-
# Allow custom python version to override testcase_pyversion.
379+
# Allow custom python version to override testfile_pyversion.
388380
if all(flag.split("=")[0] not in ["--python-version", "-2", "--py2"] for flag in flag_list):
389-
options.python_version = testcase_pyversion(testcase.file, testcase.name)
381+
options.python_version = testfile_pyversion(testcase.file)
390382

391383
if testcase.config.getoption("--mypy-verbose"):
392384
options.verbosity = testcase.config.getoption("--mypy-verbose")

mypy/test/testdaemon.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ def test_filter_out_missing_top_level_packages(self) -> None:
110110
self.make_file(td, "base/c.pyi")
111111
self.make_file(td, "base/missing.txt")
112112
self.make_file(td, "typeshed/d.pyi")
113-
self.make_file(td, "typeshed/@python2/e")
113+
self.make_file(td, "typeshed/@python2/e") # outdated
114114
self.make_file(td, "pkg1/f-stubs")
115-
self.make_file(td, "pkg2/g-python2-stubs")
115+
self.make_file(td, "pkg2/g-python2-stubs") # outdated
116116
self.make_file(td, "mpath/sub/long_name/")
117117

118118
def makepath(p: str) -> str:
@@ -128,7 +128,7 @@ def makepath(p: str) -> str:
128128
res = filter_out_missing_top_level_packages(
129129
{"a", "b", "c", "d", "e", "f", "g", "long_name", "ff", "missing"}, search, fscache
130130
)
131-
assert res == {"a", "b", "c", "d", "e", "f", "g", "long_name"}
131+
assert res == {"a", "b", "c", "d", "f", "long_name"}
132132

133133
def make_file(self, base: str, path: str) -> None:
134134
fullpath = os.path.join(base, path)

test-data/unit/README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ First install any additional dependencies needed for testing:
8585

8686
python3 -m pip install -U -r test-requirements.txt
8787

88-
You must also have a Python 2.7 binary installed that can import the `typing`
89-
module:
90-
91-
python2 -m pip install -U typing
92-
9388
The unit test suites are driven by the `pytest` framework. To run all mypy tests,
9489
run `pytest` in the mypy repository:
9590

test-data/unit/check-enum.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,15 +565,15 @@ def fn(x: F) -> None:
565565
fn(b)
566566
[out]
567567

568-
[case testFunctionalEnum_python2-skip]
568+
[case testFunctionalEnum]
569569
# TODO: Needs to have enum34 stubs somehow
570570
from enum import Enum
571571
Eu = Enum(u'Eu', u'a b')
572-
Eb = Enum(b'Eb', b'a b')
572+
Eb = Enum(b'Eb', b'a b') # E: Enum() expects a string literal as the first argument
573573
Gu = Enum(u'Gu', {u'a': 1})
574-
Gb = Enum(b'Gb', {b'a': 1})
574+
Gb = Enum(b'Gb', {b'a': 1}) # E: Enum() expects a string literal as the first argument
575575
Hu = Enum(u'Hu', [u'a'])
576-
Hb = Enum(b'Hb', [b'a'])
576+
Hb = Enum(b'Hb', [b'a']) # E: Enum() expects a string literal as the first argument
577577
Eu.a
578578
Eb.a
579579
Gu.a

test-data/unit/check-selftype.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,9 +837,10 @@ main:21: note: def do_x(cls) -> Good
837837
# Friendlier error messages for common mistakes. See #2950
838838
class A:
839839
def f(x: int) -> None: ...
840-
# def g(self: None) -> None: ... see in check-python2.test
840+
def g(self: None) -> None: ...
841841
[out]
842842
main:3: error: Self argument missing for a non-static method (or an invalid type for self)
843+
main:4: error: The erased type of self "None" is not a supertype of its class "__main__.A"
843844

844845
[case testUnionPropertyField]
845846
from typing import Union

0 commit comments

Comments
 (0)