Skip to content

Fail fast when attempting to typecheck typing.py #3725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tausackhn opened this issue Jul 17, 2017 · 9 comments
Closed

Fail fast when attempting to typecheck typing.py #3725

tausackhn opened this issue Jul 17, 2017 · 9 comments

Comments

@tausackhn
Copy link

version: 0.530-dev-1ed46189c40e4e174681f171bfe003224e934fb0
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python36-32\Scripts\mypy-script.py", line 11, in <module>
    load_entry_point('mypy===0.530-dev-1ed46189c40e4e174681f171bfe003224e934fb0', 'console_scripts', 'mypy')()
  File "c:\program files (x86)\python36-32\lib\site-packages\mypy\__main__.py", line 7, in console_entry
    main(None)
  File "c:\program files (x86)\python36-32\lib\site-packages\mypy\main.py", line 50, in main
    res = type_check_only(sources, bin_dir, options)
  File "c:\program files (x86)\python36-32\lib\site-packages\mypy\main.py", line 97, in type_check_only
    options=options)
  File "c:\program files (x86)\python36-32\lib\site-packages\mypy\build.py", line 196, in build
    graph = dispatch(sources, manager)
  File "c:\program files (x86)\python36-32\lib\site-packages\mypy\build.py", line 1801, in dispatch
    process_graph(graph, manager)
  File "c:\program files (x86)\python36-32\lib\site-packages\mypy\build.py", line 2044, in process_graph
    process_stale_scc(graph, scc, manager)
  File "c:\program files (x86)\python36-32\lib\site-packages\mypy\build.py", line 2139, in process_stale_scc
    graph[id].semantic_analysis()
  File "c:\program files (x86)\python36-32\lib\site-packages\mypy\build.py", line 1696, in semantic_analysis
    self.manager.semantic_analyzer.visit_file(self.tree, self.xpath, self.options, patches)
  File "c:\program files (x86)\python36-32\lib\site-packages\mypy\semanal.py", line 295, in visit_file
    self.accept(d)
  File "c:\program files (x86)\python36-32\lib\site-packages\mypy\semanal.py", line 3645, in accept
    node.accept(self)
  File "c:\program files (x86)\python36-32\lib\site-packages\mypy\nodes.py", line 565, in accept
    return visitor.visit_func_def(self)
  File "c:\program files (x86)\python36-32\lib\site-packages\mypy\semanal.py", line 418, in visit_func_def
    self.analyze_function(defn)
  File "c:\program files (x86)\python36-32\lib\site-packages\mypy\semanal.py", line 627, in analyze_function
    defn.body.accept(self)
  File "c:\program files (x86)\python36-32\lib\site-packages\mypy\nodes.py", line 815, in accept
    return visitor.visit_block(self)
  File "c:\program files (x86)\python36-32\lib\site-packages\mypy\semanal.py", line 1522, in visit_block
    self.accept(s)
  File "c:\program files (x86)\python36-32\lib\site-packages\mypy\semanal.py", line 3645, in accept
    node.accept(self)
  File "c:\program files (x86)\python36-32\lib\site-packages\mypy\nodes.py", line 859, in accept
    return visitor.visit_assignment_stmt(self)
  File "c:\program files (x86)\python36-32\lib\site-packages\mypy\semanal.py", line 1581, in visit_assignment_stmt
    self.process_namedtuple_definition(s)
  File "c:\program files (x86)\python36-32\lib\site-packages\mypy\semanal.py", line 2126, in process_namedtuple_definition
    named_tuple = self.check_namedtuple(s.rvalue, name)
  File "c:\program files (x86)\python36-32\lib\site-packages\mypy\semanal.py", line 2157, in check_namedtuple
    return self.build_namedtuple_typeinfo('namedtuple', [], [], {})
  File "c:\program files (x86)\python36-32\lib\site-packages\mypy\semanal.py", line 2275, in build_namedtuple_typeinfo
    info = self.basic_new_typeinfo(name, fallback)
  File "c:\program files (x86)\python36-32\lib\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
@emmatyping
Copy link
Member

Hi! Would you be able to provide some information on how you arrived at this issue? A small snippet of code would be ideal, but regardless steps to reproduce are welcome. Its difficult to figure out what is going wrong otherwise. Based on the traceback it appears to be usage of a NamedTuple?

@tausackhn
Copy link
Author

Hello, I guess the problem is in MYPYPATH=PYTHONPATH\Lib. I tried to remove MYPYPATH and now everything goes ok. But on 0.520dev the value of MYPYPATH did not influence at all.
I am sorry for earlier worry.

@JelleZijlstra
Copy link
Member

This is still a bug that we should fix, since it involves a crash. Could you share the code that reproduces the crash?

@ilevkivskyi
Copy link
Member

Could you share the code that reproduces the crash?

I think the crash is type checking the stdlib. From the error I see that __builtins__.tuple was not yet analysed at the time of the crash which is strange.

@tausackhn
Copy link
Author

Set MYPYPATH=C:\Program Files (x86)\Python36-32\Lib
Code sample:

if __name__ == '__main__':
    print("")

Full console log before traceback:

C:\Program Files (x86)\Python36-32\Lib\typing.py:1222: error: Name 'Generic' already defined on line 1203
C:\Program Files (x86)\Python36-32\Lib\typing.py:1813: error: Name 'Reversible' already defined on line 1810
C:\Program Files (x86)\Python36-32\Lib\typing.py:1843: error: Name 'AbstractSet' already defined on line 1839
C:\Program Files (x86)\Python36-32\Lib\typing.py:1858: error: Name 'Mapping' already defined on line 1854
C:\Program Files (x86)\Python36-32\Lib\typing.py:1873: error: Name 'Sequence' already defined on line 1869
C:\Program Files (x86)\Python36-32\Lib\typing.py:1877: error: Name 'Sequence' already defined on line 1873
C:\Program Files (x86)\Python36-32\Lib\typing.py:1956: error: Name 'ContextManager' already defined on line 1953
C:\Program Files (x86)\Python36-32\Lib\functools.py:28: error: Name 'RLock' already defined (possibly by an import)
C:\Program Files (x86)\Python36-32\Lib\collections\__init__.py:35: error: Cannot find module named '_collections'
C:\Program Files (x86)\Python36-32\Lib\collections\__init__.py:35: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help)
C:\Program Files (x86)\Python36-32\Lib\functools.py:17: error: Cannot find module named '_functools'
C:\Program Files (x86)\Python36-32\Lib\enum.py:509: error: Name 'Enum' already defined on line 109
C:\Program Files (x86)\Python36-32\Lib\re.py:127: error: Cannot find module named '_locale'
C:\Program Files (x86)\Python36-32\Lib\copy.py:60: error: Cannot find module named 'org.python.core'
C:\Program Files (x86)\Python36-32\Lib\sre_compile.py:13: error: Cannot find module named '_sre'
C:\Program Files (x86)\Python36-32\Lib\sre_constants.py:18: error: Cannot find module named '_sre'
C:\Program Files (x86)\Python36-32\Lib\os.py:71: error: Cannot find module named 'nt'
C:\Program Files (x86)\Python36-32\Lib\pdb.py:1530: error: Cannot find module named '__main__'
C:\Program Files (x86)\Python36-32\Lib\io.py:51: error: Cannot find module named '_io'
C:\Program Files (x86)\Python36-32\Lib\pickle.py:1562: error: Cannot find module named '_pickle'
C:\Program Files (x86)\Python36-32\Lib\locale.py:108: error: Name 'localeconv' already defined
C:\Program Files (x86)\Python36-32\Lib\locale.py:583: error: Name 'setlocale' already defined on line 87
C:\Program Files (x86)\Python36-32\Lib\importlib\__init__.py:16: error: Cannot find module named '_frozen_importlib'
C:\Program Files (x86)\Python36-32\Lib\importlib\__init__.py:34: error: Cannot find module named '_frozen_importlib_external'
C:\Program Files (x86)\Python36-32\Lib\subprocess.py:128: error: Cannot find module named '_winapi'
C:\Program Files (x86)\Python36-32\Lib\bdb.py:422: error: Cannot find module named '__main__'
C:\Program Files (x86)\Python36-32\Lib\signal.py:1: error: Cannot find module named '_signal'
C:\Program Files (x86)\Python36-32\Lib\struct.py:13: error: Cannot find module named '_struct'
C:\Program Files (x86)\Python36-32\Lib\opcode.py:19: error: Cannot find module named '_opcode'
C:\Program Files (x86)\Python36-32\Lib\importlib\_bootstrap.py:1144: error: Cannot find module named '_frozen_importlib_external' C:\Program Files (x86)\Python36-32\Lib\string.py:21: error: Cannot find module named '_string'
C:\Program Files (x86)\Python36-32\Lib\dummy_threading.py:51: error: Cannot find module named '_dummy_threading'
C:\Program Files (x86)\Python36-32\Lib\platform.py:506: error: Cannot find module named 'winreg'
C:\Program Files (x86)\Python36-32\Lib\platform.py:508: error: Cannot find module named '_winreg'
C:\Program Files (x86)\Python36-32\Lib\platform.py:591: error: Cannot find module named 'java.lang'
C:\Program Files (x86)\Python36-32\Lib\platform.py:614: error: Cannot find module named 'java'
C:\Program Files (x86)\Python36-32\Lib\platform.py:990: error: Cannot find module named 'vms_lib'
C:\Program Files (x86)\Python36-32\Lib\socket.py:49: error: Cannot find module named '_socket'
C:\Program Files (x86)\Python36-32\Lib\datetime.py:2263: error: Cannot find module named '_datetime'
C:\Program Files (x86)\Python36-32\Lib\xml\parsers\expat.py:4: error: No library stub file for standard library module 'pyexpat'
C:\Program Files (x86)\Python36-32\Lib\xml\parsers\expat.py:4: note: (Stub files are from https://github.com/python/typeshed)
C:\Program Files (x86)\Python36-32\Lib\bz2.py:23: error: Cannot find module named '_bz2'
C:\Program Files (x86)\Python36-32\Lib\lzma.py:27: error: Cannot find module named '_lzma'
C:\Program Files (x86)\Python36-32\Lib\hashlib.py:80: error: Cannot find module named '_sha1'
C:\Program Files (x86)\Python36-32\Lib\hashlib.py:83: error: Cannot find module named '_md5'
C:\Program Files (x86)\Python36-32\Lib\hashlib.py:86: error: Cannot find module named '_sha256'
C:\Program Files (x86)\Python36-32\Lib\hashlib.py:90: error: Cannot find module named '_sha512'
C:\Program Files (x86)\Python36-32\Lib\hashlib.py:94: error: Cannot find module named '_blake2'
C:\Program Files (x86)\Python36-32\Lib\hashlib.py:99: error: Cannot find module named '_sha3'
C:\Program Files (x86)\Python36-32\Lib\hashlib.py:159: error: Cannot find module named '_hashlib'
C:\Program Files (x86)\Python36-32\Lib\ssl.py:101: error: Cannot find module named '_ssl'
C:\Program Files (x86)\Python36-32\Lib\typing.py:12: error: Name 'collections_abc' already defined
C:\Program Files (x86)\Python36-32\Lib\typing.py:16: error: Module 'types' has no attribute 'WrapperDescriptorType'
C:\Program Files (x86)\Python36-32\Lib\typing.py:16: error: Module 'types' has no attribute 'MethodWrapperType'
C:\Program Files (x86)\Python36-32\Lib\typing.py:16: error: Module 'types' has no attribute 'MethodDescriptorType'
C:\Program Files (x86)\Python36-32\Lib\typing.py:1829: error: Invalid type "typing.Sized"
C:\Program Files (x86)\Python36-32\Lib\typing.py:1829: error: Invalid base class
C:\Program Files (x86)\Python36-32\Lib\typing.py:1843: error: Invalid type "typing.Sized"
C:\Program Files (x86)\Python36-32\Lib\typing.py:1843: error: Invalid base class
C:\Program Files (x86)\Python36-32\Lib\typing.py:1858: error: Invalid type "typing.Sized"
C:\Program Files (x86)\Python36-32\Lib\typing.py:1858: error: Invalid base class
C:\Program Files (x86)\Python36-32\Lib\typing.py:1873: error: Invalid type "typing.Sized"
C:\Program Files (x86)\Python36-32\Lib\typing.py:1873: error: Invalid base class
C:\Program Files (x86)\Python36-32\Lib\typing.py:1877: error: Invalid type "typing.Sized"
C:\Program Files (x86)\Python36-32\Lib\typing.py:1877: error: Invalid base class
C:\Program Files (x86)\Python36-32\Lib\typing.py:1932: error: Invalid type "typing.Sized"
C:\Program Files (x86)\Python36-32\Lib\typing.py:1932: error: Invalid base class
C:\Program Files (x86)\Python36-32\Lib\typing.py:2122: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues

@ilevkivskyi
Copy link
Member

OK, then this is duplicate of #3131 (closed now). Maybe we could try to generate a reasonable error when a user tries to typecheck typing.py?

@ilevkivskyi ilevkivskyi marked this as a duplicate of #3131 Jul 17, 2017
@ilevkivskyi ilevkivskyi changed the title Internal error after updating from 0.520dev to 0.530dev Fail fast when attempting to typecheck typing.py Sep 29, 2017
@emmatyping
Copy link
Member

We now fail fast when trying to add site-packages to the PATH. Would that be enough to consider this as solved?

@ilevkivskyi
Copy link
Member

Do you mean PATH or MYPYPATH? Or both? Or do we fail fast if we find site-packages wherever on search paths (excluding PEP 561 of course)? If this is the latter, then I think we can close this.

@emmatyping
Copy link
Member

In #5301 I modified things so that if any PATH except the PEP 561 search path contained site-packages, we would fail fast. I will close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants