diff --git a/mypy/build.py b/mypy/build.py index e6f597af31bc..eaa10063df2d 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -40,7 +40,6 @@ ) if TYPE_CHECKING: from mypy.report import Reports # Avoid unconditional slow import -from mypy import moduleinfo from mypy.fixup import fixup_module from mypy.modulefinder import ( BuildSource, compute_search_paths, FindModuleCache, SearchPaths, ModuleSearchResult, @@ -2498,11 +2497,6 @@ def module_not_found(manager: BuildManager, line: int, caller_state: State, errors.report(line, 0, "Cannot find 'builtins' module. Typeshed appears broken!", blocker=True) errors.raise_error() - elif moduleinfo.is_std_lib_module(manager.options.python_version, target): - msg = "No library stub file for standard library module '{}'".format(target) - note = "(Stub files are from https://github.com/python/typeshed)" - errors.report(line, 0, msg, code=codes.IMPORT) - errors.report(line, 0, note, severity='note', only_once=True, code=codes.IMPORT) else: msg, note = reason.error_message_templates() errors.report(line, 0, msg.format(target), code=codes.IMPORT) diff --git a/mypy/moduleinfo.py b/mypy/moduleinfo.py deleted file mode 100644 index 9cf45784ff04..000000000000 --- a/mypy/moduleinfo.py +++ /dev/null @@ -1,357 +0,0 @@ -"""Collection of names of notable Python library modules. - -Both standard library and third party modules are included. The -selection criteria for third party modules is somewhat arbitrary. - -For packages we usually just include the top-level package name, but -sometimes some or all submodules are enumerated. In the latter case if -the top-level name is included we include all possible submodules -(this is an implementation limitation). - -These are used to give more useful error messages when there is -no stub for a module. -""" - -from typing import Set, Tuple -from typing_extensions import Final - -# Modules and packages common to Python 2.7 and 3.x. -common_std_lib_modules = { - 'abc', - 'aifc', - 'antigravity', - 'argparse', - 'array', - 'ast', - 'asynchat', - 'asyncore', - 'audioop', - 'base64', - 'bdb', - 'binascii', - 'binhex', - 'bisect', - 'bz2', - 'cProfile', - 'calendar', - 'cgi', - 'cgitb', - 'chunk', - 'cmath', - 'cmd', - 'code', - 'codecs', - 'codeop', - 'collections', - 'colorsys', - 'compileall', - 'contextlib', - 'copy', - 'crypt', - 'csv', - 'ctypes', - 'curses', - 'datetime', - 'decimal', - 'difflib', - 'dis', - 'distutils', - 'doctest', - 'dummy_threading', - 'email', - 'encodings', - 'fcntl', - 'filecmp', - 'fileinput', - 'fnmatch', - 'formatter', - 'fractions', - 'ftplib', - 'functools', - 'genericpath', - 'getopt', - 'getpass', - 'gettext', - 'glob', - 'grp', - 'gzip', - 'hashlib', - 'heapq', - 'hmac', - 'imaplib', - 'imghdr', - 'importlib', - 'inspect', - 'io', - 'json', - 'keyword', - 'lib2to3', - 'linecache', - 'locale', - 'logging', - 'macpath', - 'macurl2path', - 'mailbox', - 'mailcap', - 'math', - 'mimetypes', - 'mmap', - 'modulefinder', - 'msilib', - 'multiprocessing', - 'netrc', - 'nis', - 'nntplib', - 'ntpath', - 'nturl2path', - 'numbers', - 'opcode', - 'operator', - 'optparse', - 'os', - 'ossaudiodev', - 'parser', - 'pdb', - 'pickle', - 'pickletools', - 'pipes', - 'pkgutil', - 'platform', - 'plistlib', - 'poplib', - 'posixpath', - 'pprint', - 'profile', - 'pstats', - 'pty', - 'py_compile', - 'pyclbr', - 'pydoc', - 'pydoc_data', - 'pyexpat', - 'quopri', - 'random', - 're', - 'resource', - 'rlcompleter', - 'runpy', - 'sched', - 'select', - 'shelve', - 'shlex', - 'shutil', - 'site', - 'smtpd', - 'smtplib', - 'sndhdr', - 'socket', - 'spwd', - 'sqlite3', - 'sqlite3.dbapi2', - 'sqlite3.dump', - 'sre_compile', - 'sre_constants', - 'sre_parse', - 'ssl', - 'stat', - 'string', - 'stringprep', - 'struct', - 'subprocess', - 'sunau', - 'symbol', - 'symtable', - 'sysconfig', - 'syslog', - 'tabnanny', - 'tarfile', - 'telnetlib', - 'tempfile', - 'termios', - 'textwrap', - 'this', - 'threading', - 'timeit', - 'token', - 'tokenize', - 'trace', - 'traceback', - 'tty', - 'types', - 'unicodedata', - 'unittest', - 'urllib', - 'uu', - 'uuid', - 'warnings', - 'wave', - 'weakref', - 'webbrowser', - 'wsgiref', - 'xdrlib', - 'xml.dom', - 'xml.dom.NodeFilter', - 'xml.dom.domreg', - 'xml.dom.expatbuilder', - 'xml.dom.minicompat', - 'xml.dom.minidom', - 'xml.dom.pulldom', - 'xml.dom.xmlbuilder', - 'xml.etree', - 'xml.etree.ElementInclude', - 'xml.etree.ElementPath', - 'xml.etree.ElementTree', - 'xml.etree.cElementTree', - 'xml.parsers', - 'xml.parsers.expat', - 'xml.sax', - 'xml.sax._exceptions', - 'xml.sax.expatreader', - 'xml.sax.handler', - 'xml.sax.saxutils', - 'xml.sax.xmlreader', - 'zipfile', - 'zlib', - # fake names to use in tests - '__dummy_stdlib1', - '__dummy_stdlib2', -} # type: Final - -# Python 2 standard library modules. -python2_std_lib_modules = common_std_lib_modules | { - 'BaseHTTPServer', - 'Bastion', - 'CGIHTTPServer', - 'ConfigParser', - 'Cookie', - 'DocXMLRPCServer', - 'HTMLParser', - 'MimeWriter', - 'Queue', - 'SimpleHTTPServer', - 'SimpleXMLRPCServer', - 'SocketServer', - 'StringIO', - 'UserDict', - 'UserList', - 'UserString', - 'anydbm', - 'atexit', - 'audiodev', - 'bsddb', - 'cPickle', - 'cStringIO', - 'commands', - 'cookielib', - 'copy_reg', - 'curses.wrapper', - 'dbhash', - 'dircache', - 'dumbdbm', - 'dummy_thread', - 'fpformat', - 'future_builtins', - 'hotshot', - 'htmlentitydefs', - 'htmllib', - 'httplib', - 'ihooks', - 'imputil', - 'itertools', - 'linuxaudiodev', - 'markupbase', - 'md5', - 'mhlib', - 'mimetools', - 'mimify', - 'multifile', - 'multiprocessing.forking', - 'mutex', - 'new', - 'os2emxpath', - 'popen2', - 'posixfile', - 'repr', - 'rexec', - 'rfc822', - 'robotparser', - 'sets', - 'sgmllib', - 'sha', - 'sre', - 'statvfs', - 'stringold', - 'strop', - 'sunaudio', - 'time', - 'toaiff', - 'urllib2', - 'urlparse', - 'user', - 'whichdb', - 'xmllib', - 'xmlrpclib', -} # type: Final - -# Python 3 standard library modules (based on Python 3.5.0). -python3_std_lib_modules = common_std_lib_modules | { - 'asyncio', - 'collections.abc', - 'concurrent', - 'concurrent.futures', - 'configparser', - 'copyreg', - 'dbm', - 'ensurepip', - 'enum', - 'html', - 'http', - 'imp', - 'ipaddress', - 'lzma', - 'pathlib', - 'queue', - 'readline', - 'reprlib', - 'selectors', - 'signal', - 'socketserver', - 'statistics', - 'tkinter', - 'tracemalloc', - 'turtle', - 'turtledemo', - 'typing', - 'unittest.mock', - 'urllib.error', - 'urllib.parse', - 'urllib.request', - 'urllib.response', - 'urllib.robotparser', - 'venv', - 'xmlrpc', - 'xxlimited', - 'zipapp', -} # type: Final - - -def is_std_lib_module(python_version: Tuple[int, int], id: str) -> bool: - if python_version[0] == 2: - return is_in_module_collection(python2_std_lib_modules, id) - elif python_version[0] >= 3: - return is_in_module_collection(python3_std_lib_modules, id) - else: - # TODO: Raise an exception here? - return False - - -def is_py3_std_lib_module(id: str) -> bool: - return is_in_module_collection(python3_std_lib_modules, id) - - -def is_in_module_collection(collection: Set[str], id: str) -> bool: - components = id.split('.') - for prefix_length in range(1, len(components) + 1): - if '.'.join(components[:prefix_length]) in collection: - return True - return False diff --git a/mypy/test/testmoduleinfo.py b/mypy/test/testmoduleinfo.py deleted file mode 100644 index 329eccc285ed..000000000000 --- a/mypy/test/testmoduleinfo.py +++ /dev/null @@ -1,12 +0,0 @@ -from mypy import moduleinfo -from mypy.test.helpers import assert_true, assert_false, Suite - - -class ModuleInfoSuite(Suite): - def test_is_in_module_collection(self) -> None: - assert_true(moduleinfo.is_in_module_collection({'foo'}, 'foo')) - assert_true(moduleinfo.is_in_module_collection({'foo'}, 'foo.bar')) - assert_false(moduleinfo.is_in_module_collection({'foo'}, 'fo')) - assert_true(moduleinfo.is_in_module_collection({'foo.bar'}, 'foo.bar')) - assert_true(moduleinfo.is_in_module_collection({'foo.bar'}, 'foo.bar.zar')) - assert_false(moduleinfo.is_in_module_collection({'foo.bar'}, 'foo')) diff --git a/test-data/unit/check-python2.test b/test-data/unit/check-python2.test index 06b8f419e114..51ab5f96c655 100644 --- a/test-data/unit/check-python2.test +++ b/test-data/unit/check-python2.test @@ -163,15 +163,6 @@ main:8: error: Argument 2 to "f" has incompatible type "int"; expected "Tuple[in [case testBackquoteExpr] `1`.x # E: "str" has no attribute "x" -[case testPython2OnlyStdLibModuleWithoutStub] -import asyncio -import Bastion -[out] -main:1: error: Cannot find implementation or library stub for module named 'asyncio' -main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports -main:2: error: No library stub file for standard library module 'Bastion' -main:2: note: (Stub files are from https://github.com/python/typeshed) - [case testImportFromPython2Builtin] from __builtin__ import int as i x = 1 # type: i diff --git a/test-data/unit/semanal-errors.test b/test-data/unit/semanal-errors.test index 319604efb0b2..f6446b87c24a 100644 --- a/test-data/unit/semanal-errors.test +++ b/test-data/unit/semanal-errors.test @@ -1289,20 +1289,6 @@ x = 1 y = 1 [out] -[case testMissingStubForStdLibModule] -import __dummy_stdlib1 -[out] -main:1: error: No library stub file for standard library module '__dummy_stdlib1' -main:1: note: (Stub files are from https://github.com/python/typeshed) - -[case testMissingStubForTwoModules] -import __dummy_stdlib1 -import __dummy_stdlib2 -[out] -main:1: error: No library stub file for standard library module '__dummy_stdlib1' -main:1: note: (Stub files are from https://github.com/python/typeshed) -main:2: error: No library stub file for standard library module '__dummy_stdlib2' - [case testListComprehensionSpecialScoping] class A: x = 1