python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.48k stars 2.83k forks source link

typing.py:2122: error: INTERNAL ERROR -- please report a bug #4014

Closed dilyanpalauzov closed 7 years ago

dilyanpalauzov commented 7 years ago

I have mypy 0.521, python 3.5.4+ (12-g44c1b62), typing 3.6.2, Django 1.11.5 and djangorestframework 3.6.4.

I want to analyze this file

from rest_framework.request  import Request as DRFRequest
from django.http import HttpRequest as DjangoRequest

def x(f: DjangoRequest) -> None: print(type(f))

a = DjangoRequest()
type(a)
b = DRFRequest(a)
type(b)
x(a)
x(b)

and run MYPYPATH=/opt/virtualenv/django/lib/python3.5/site-packages/ mypy --strict --show-traceback x.py which emits on the standard error:

/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:2122: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:2122: note: use --pdb to drop into pdb

and on stdout


/opt/virtualenv/django/lib/python3.5/site-packages/django/http/cookie.py:24: error: Name 'SimpleCookie' already defined on line 20
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:1222: error: Name 'Generic' already defined on line 1203
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:1813: error: Name 'Reversible' already defined on line 1810
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:1843: error: Name 'AbstractSet' already defined on line 1839
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:1858: error: Name 'Mapping' already defined on line 1854
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:1873: error: Name 'Sequence' already defined on line 1869
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:1877: error: Name 'Sequence' already defined on line 1873
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:1956: error: Name 'ContextManager' already defined on line 1953
/opt/virtualenv/django/lib/python3.5/site-packages/django/http/multipartparser.py:24: error: No library stub file for module 'django.utils.six.moves.urllib.parse'
/opt/virtualenv/django/lib/python3.5/site-packages/django/http/multipartparser.py:24: note: (Stub files are from https://github.com/python/typeshed)
/opt/virtualenv/django/lib/python3.5/site-packages/django/http/request.py:22: error: No library stub file for module 'django.utils.six.moves.urllib.parse'
/opt/virtualenv/django/lib/python3.5/site-packages/django/http/cookie.py:7: error: No library stub file for module 'django.utils.six.moves'
/opt/virtualenv/django/lib/python3.5/site-packages/django/http/response.py:20: error: No library stub file for module 'django.utils.six.moves'
/opt/virtualenv/django/lib/python3.5/site-packages/django/http/response.py:21: error: No library stub file for module 'django.utils.six.moves.http_client'
/opt/virtualenv/django/lib/python3.5/site-packages/django/http/response.py:22: error: No library stub file for module 'django.utils.six.moves.urllib.parse'
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:14: error: Cannot find module named '_collections_abc'
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:14: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help)
/opt/virtualenv/django/lib/python3.5/site-packages/django/utils/encoding.py:11: error: No library stub file for module 'django.utils.six.moves.urllib.parse'
/opt/virtualenv/django/lib/python3.5/site-packages/django/utils/text.py:14: error: No library stub file for module 'django.utils.six.moves'
/opt/virtualenv/django/lib/python3.5/site-packages/django/utils/decorators.py:177: error: Name 'ContextDecorator' already defined (possibly by an import)
/opt/virtualenv/django/lib/python3.5/site-packages/django/forms/renderers.py:49: error: Name 'DjangoTemplates' already defined (possibly by an import)
/opt/virtualenv/django/lib/python3.5/site-packages/django/forms/renderers.py:57: error: Name 'Jinja2' already defined (possibly by an import)
/opt/virtualenv/django/lib/python3.5/site-packages/pytz/__init__.py:245: error: Cannot assign to a type
/opt/virtualenv/django/lib/python3.5/site-packages/rest_framework/compat.py:32: error: Cannot find module named 'urlparse'
/opt/virtualenv/django/lib/python3.5/site-packages/requests/__init__.py:114: error: Name 'NullHandler' already defined (possibly by an import)
/opt/virtualenv/django/lib/python3.5/site-packages/rest_framework/compat.py:211: error: Cannot find module named 'guardian'
/opt/virtualenv/django/lib/python3.5/site-packages/django/test/__init__.py:27: error: No library stub file for module 'mock'
/opt/virtualenv/django/lib/python3.5/site-packages/coreapi/utils.py:162: error: Cannot assign to a type
/opt/virtualenv/django/lib/python3.5/site-packages/urllib3/__init__.py:29: error: Name 'NullHandler' already defined (possibly by an import)
/opt/virtualenv/django/lib/python3.5/site-packages/django/test/testcases.py:14: error: No library stub file for standard library module 'unittest.util'
/opt/virtualenv/django/lib/python3.5/site-packages/django/test/testcases.py:44: error: No library stub file for module 'django.utils.six.moves.urllib.request'
/opt/virtualenv/django/lib/python3.5/site-packages/django/test/utils.py:10: error: No library stub file for standard library module 'xml.dom.minidom'
/opt/virtualenv/django/lib/python3.5/site-packages/django/utils/autoreload.py:61: error: Cannot find module named 'pyinotify'
/opt/virtualenv/django/lib/python3.5/site-packages/django/utils/autoreload.py:322: error: Cannot find module named '_systemrestart'
/opt/virtualenv/django/lib/python3.5/site-packages/django/core/files/locks.py:31: error: No library stub file for standard library module 'ctypes'
/opt/virtualenv/django/lib/python3.5/site-packages/django/core/files/locks.py:33: error: No library stub file for standard library module 'ctypes.wintypes'
/opt/virtualenv/django/lib/python3.5/site-packages/django/utils/html_parser.py:8: error: Name 'HTMLParseError' already defined on line 5
/opt/virtualenv/django/lib/python3.5/site-packages/pytz/lazy.py:3: error: Cannot find module named 'UserDict'
/opt/virtualenv/django/lib/python3.5/site-packages/pytz/tzinfo.py:8: error: Cannot find module named 'sets'
/opt/virtualenv/django/lib/python3.5/site-packages/pytz/tzfile.py:7: error: Cannot find module named 'cStringIO'
/opt/virtualenv/django/lib/python3.5/site-packages/pkg_resources/__init__.py:51: error: No library stub file for module 'pkg_resources.extern.six.moves'
/opt/virtualenv/django/lib/python3.5/site-packages/pkg_resources/__init__.py:657: error: Cannot find module named '__main__'
/opt/virtualenv/django/lib/python3.5/site-packages/OpenSSL/SSL.py:33: error: Name '_memoryview' already defined on line 31
/opt/virtualenv/django/lib/python3.5/site-packages/OpenSSL/SSL.py:39: error: Name '_buffer' already defined on line 37
/opt/virtualenv/django/lib/python3.5/site-packages/urllib3/exceptions.py:2: error: No library stub file for module 'urllib3.packages.six.moves.http_client'
/opt/virtualenv/django/lib/python3.5/site-packages/requests/utils.py:47: error: Cannot find module named 'winreg'
/opt/virtualenv/django/lib/python3.5/site-packages/requests/utils.py:49: error: Cannot find module named '_winreg'
/opt/virtualenv/django/lib/python3.5/site-packages/requests/utils.py:164: error: No library stub file for standard library module 'netrc'
/opt/virtualenv/django/lib/python3.5/site-packages/requests/models.py:17: error: Cannot find module named 'encodings.idna'
/opt/virtualenv/django/lib/python3.5/site-packages/markdown/inlinepatterns.py:56: error: Cannot find module named 'htmlentitydefs'
/opt/virtualenv/django/lib/python3.5/site-packages/pygments/cmdline.py:488: error: No library stub file for module 'colorama'
/opt/virtualenv/django/lib/python3.5/site-packages/pygments/cmdline.py:488: error: No library stub file for module 'colorama.initialise'
/opt/virtualenv/django/lib/python3.5/site-packages/PIL/Image.py:101: error: Cannot find module named '__builtin__'
/opt/virtualenv/django/lib/python3.5/site-packages/psycopg2/extras.py:44: error: No library stub file for module 'psycopg2._psycopg'
/opt/virtualenv/django/lib/python3.5/site-packages/coreapi/compat.py:15: error: Cannot find module named 'cookielib'
/opt/virtualenv/django/lib/python3.5/site-packages/urllib3/connectionpool.py:28: error: No library stub file for module 'urllib3.packages.six.moves'
/opt/virtualenv/django/lib/python3.5/site-packages/urllib3/connection.py:19: error: Name 'BaseSSLError' already defined on line 15
/opt/virtualenv/django/lib/python3.5/site-packages/urllib3/connection.py:27: error: Name 'ConnectionError' already defined on line 25
/opt/virtualenv/django/lib/python3.5/site-packages/urllib3/connection.py:371: error: Cannot assign to a type
/opt/virtualenv/django/lib/python3.5/site-packages/urllib3/connection.py:373: error: Cannot assign to a type
/opt/virtualenv/django/lib/python3.5/site-packages/urllib3/_collections.py:6: error: Name 'RLock' already defined (possibly by an import)
/opt/virtualenv/django/lib/python3.5/site-packages/urllib3/poolmanager.py:10: error: No library stub file for module 'urllib3.packages.six.moves.urllib.parse'
/opt/virtualenv/django/lib/python3.5/site-packages/urllib3/response.py:15: error: No library stub file for module 'urllib3.packages.six.moves'
/opt/virtualenv/django/lib/python3.5/site-packages/cryptography/hazmat/primitives/hashes.py:152: error: Cannot assign to a type
/opt/virtualenv/django/lib/python3.5/site-packages/cryptography/hazmat/primitives/hashes.py:167: error: Cannot assign to a type
/opt/virtualenv/django/lib/python3.5/site-packages/urllib3/util/ssl_.py:95: error: Name 'SSLContext' already defined on line 12
/opt/virtualenv/django/lib/python3.5/site-packages/requests/compat.py:42: error: Cannot find module named 'urllib2'
/opt/virtualenv/django/lib/python3.5/site-packages/requests/compat.py:43: error: Cannot find module named 'cookielib'
/opt/virtualenv/django/lib/python3.5/site-packages/requests/compat.py:44: error: Cannot find module named 'Cookie'
/opt/virtualenv/django/lib/python3.5/site-packages/requests/compat.py:45: error: Cannot find module named 'StringIO'
/opt/virtualenv/django/lib/python3.5/site-packages/requests/cookies.py:23: error: No library stub file for standard library module 'dummy_threading'
/opt/virtualenv/django/lib/python3.5/site-packages/PIL/ImageQt.py:26: error: No library stub file for module 'PyQt5.QtGui'
/opt/virtualenv/django/lib/python3.5/site-packages/PIL/ImageQt.py:27: error: No library stub file for module 'PyQt5.QtCore'
/opt/virtualenv/django/lib/python3.5/site-packages/PIL/ImageQt.py:31: error: No library stub file for module 'PyQt4.QtGui'
/opt/virtualenv/django/lib/python3.5/site-packages/PIL/ImageQt.py:32: error: No library stub file for module 'PyQt4.QtCore'
/opt/virtualenv/django/lib/python3.5/site-packages/PIL/ImageQt.py:36: error: Cannot find module named 'PySide.QtGui'
/opt/virtualenv/django/lib/python3.5/site-packages/PIL/ImageQt.py:37: error: Cannot find module named 'PySide.QtCore'
/opt/virtualenv/django/lib/python3.5/site-packages/django/forms/utils.py:16: error: Cannot find module named 'UserList'
/opt/virtualenv/django/lib/python3.5/site-packages/jinja2/utils.py:182: error: Cannot find module named 'pretty'
/opt/virtualenv/django/lib/python3.5/site-packages/psycopg2/__init__.py:50: error: No library stub file for module 'psycopg2._psycopg'
/opt/virtualenv/django/lib/python3.5/site-packages/psycopg2/extensions.py:37: error: No library stub file for module 'psycopg2._psycopg'
/opt/virtualenv/django/lib/python3.5/site-packages/urllib3/request.py:4: error: No library stub file for module 'urllib3.packages.six.moves.urllib.parse'
/opt/virtualenv/django/lib/python3.5/site-packages/cryptography/hazmat/bindings/openssl/binding.py:13: error: Cannot find module named 'cryptography.hazmat.bindings._openssl'
/opt/virtualenv/django/lib/python3.5/site-packages/cryptography/hazmat/primitives/constant_time.py:9: error: Cannot find module named 'cryptography.hazmat.bindings._constant_time'
/opt/virtualenv/django/lib/python3.5/site-packages/simplejson/__init__.py:125: error: No library stub file for module 'simplejson._speedups'
/opt/virtualenv/django/lib/python3.5/site-packages/urllib3/packages/ordered_dict.py:6: error: Cannot find module named 'thread'
/opt/virtualenv/django/lib/python3.5/site-packages/urllib3/packages/ordered_dict.py:8: error: Cannot find module named 'dummy_thread'
/opt/virtualenv/django/lib/python3.5/site-packages/urllib3/packages/ordered_dict.py:11: error: Cannot find module named '_abcoll'
/opt/virtualenv/django/lib/python3.5/site-packages/cffi/api.py:46: error: Cannot find module named '_cffi_backend'
/opt/virtualenv/django/lib/python3.5/site-packages/cffi/api.py:780: error: No library stub file for standard library module 'ctypes.util'
/opt/virtualenv/django/lib/python3.5/site-packages/jinja2/debug.py:22: error: Cannot find module named '__pypy__'
/opt/virtualenv/django/lib/python3.5/site-packages/jinja2/debug.py:105: error: No library stub file for module 'jinja2.debugrenderer'
/opt/virtualenv/django/lib/python3.5/site-packages/simplejson/scanner.py:6: error: No library stub file for module 'simplejson._speedups'
/opt/virtualenv/django/lib/python3.5/site-packages/simplejson/decoder.py:12: error: No library stub file for module 'simplejson._speedups'
/opt/virtualenv/django/lib/python3.5/site-packages/socks.py:71: error: Cannot find module named 'win_inet_pton'
/opt/virtualenv/django/lib/python3.5/site-packages/cffi/recompiler.py:1532: error: Cannot find module named 'testing.udir'
/opt/virtualenv/django/lib/python3.5/site-packages/pycparser/ply/yacc.py:2000: error: Cannot find module named 'cPickle'
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:12: error: Name 'collections_abc' already defined
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:16: error: Module 'types' has no attribute 'WrapperDescriptorType'
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:16: error: Module 'types' has no attribute 'MethodWrapperType'
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:16: error: Module 'types' has no attribute 'MethodDescriptorType'
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:1829: error: Invalid type "typing.Sized"
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:1829: error: Invalid base class
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:1843: error: Invalid type "typing.Sized"
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:1843: error: Invalid base class
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:1858: error: Invalid type "typing.Sized"
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:1858: error: Invalid base class
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:1873: error: Invalid type "typing.Sized"
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:1873: error: Invalid base class
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:1877: error: Invalid type "typing.Sized"
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:1877: error: Invalid base class
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:1932: error: Invalid type "typing.Sized"
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:1932: error: Invalid base class
/opt/virtualenv/django/lib/python3.5/site-packages/typing.py:2122: error: namedtuple() expects a string literal as the first argument
Traceback (most recent call last):
  File "/opt/virtualenv/django/bin/mypy", line 11, in <module>
    sys.exit(console_entry())
  File "/opt/virtualenv/django/lib/python3.5/site-packages/mypy/__main__.py", line 7, in console_entry
    main(None)
  File "/opt/virtualenv/django/lib/python3.5/site-packages/mypy/main.py", line 50, in main
    res = type_check_only(sources, bin_dir, options)
  File "/opt/virtualenv/django/lib/python3.5/site-packages/mypy/main.py", line 97, in type_check_only
    options=options)
  File "/opt/virtualenv/django/lib/python3.5/site-packages/mypy/build.py", line 196, in build
    graph = dispatch(sources, manager)
  File "/opt/virtualenv/django/lib/python3.5/site-packages/mypy/build.py", line 1801, in dispatch
    process_graph(graph, manager)
  File "/opt/virtualenv/django/lib/python3.5/site-packages/mypy/build.py", line 2044, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/opt/virtualenv/django/lib/python3.5/site-packages/mypy/build.py", line 2139, in process_stale_scc
    graph[id].semantic_analysis()
  File "/opt/virtualenv/django/lib/python3.5/site-packages/mypy/build.py", line 1696, in semantic_analysis
    self.manager.semantic_analyzer.visit_file(self.tree, self.xpath, self.options, patches)
  File "/opt/virtualenv/django/lib/python3.5/site-packages/mypy/semanal.py", line 295, in visit_file
    self.accept(d)
  File "/opt/virtualenv/django/lib/python3.5/site-packages/mypy/semanal.py", line 3645, in accept
    node.accept(self)
  File "/opt/virtualenv/django/lib/python3.5/site-packages/mypy/nodes.py", line 565, in accept
    return visitor.visit_func_def(self)
  File "/opt/virtualenv/django/lib/python3.5/site-packages/mypy/semanal.py", line 418, in visit_func_def
    self.analyze_function(defn)
  File "/opt/virtualenv/django/lib/python3.5/site-packages/mypy/semanal.py", line 627, in analyze_function
    defn.body.accept(self)
  File "/opt/virtualenv/django/lib/python3.5/site-packages/mypy/nodes.py", line 815, in accept
    return visitor.visit_block(self)
  File "/opt/virtualenv/django/lib/python3.5/site-packages/mypy/semanal.py", line 1522, in visit_block
    self.accept(s)
  File "/opt/virtualenv/django/lib/python3.5/site-packages/mypy/semanal.py", line 3645, in accept
    node.accept(self)
  File "/opt/virtualenv/django/lib/python3.5/site-packages/mypy/nodes.py", line 859, in accept
    return visitor.visit_assignment_stmt(self)
  File "/opt/virtualenv/django/lib/python3.5/site-packages/mypy/semanal.py", line 1581, in visit_assignment_stmt
    self.process_namedtuple_definition(s)
  File "/opt/virtualenv/django/lib/python3.5/site-packages/mypy/semanal.py", line 2126, in process_namedtuple_definition
    named_tuple = self.check_namedtuple(s.rvalue, name)
  File "/opt/virtualenv/django/lib/python3.5/site-packages/mypy/semanal.py", line 2157, in check_namedtuple
    return self.build_namedtuple_typeinfo('namedtuple', [], [], {})
  File "/opt/virtualenv/django/lib/python3.5/site-packages/mypy/semanal.py", line 2275, in build_namedtuple_typeinfo
    info = self.basic_new_typeinfo(name, fallback)
  File "/opt/virtualenv/django/lib/python3.5/site-packages/mypy/semanal.py", line 2251, in basic_new_typeinfo
    info.mro = [info] + basetype_or_fallback.type.mro
TypeError: can only concatenate list (not "NoneType") to list

What is wrong?

ethanhs commented 7 years ago

This is a duplicate of #3725. The answer is you aren't supposed to point to your site-packages directory, for multiple reasons.