Skip to content

__builtins__ and int are not defined #3867

Closed
@diamond-lizard

Description

@diamond-lizard

When I run mypy against this test program ("foo.py"):

def gcd(a: int, b: int) -> int:
  while b:
    a, b = b, a % b
  return a

print(gcd( 'x', 15 ))

I get this error:

foo.py: error: Name '__builtins__' is not defined
foo.py:1: error: Name 'int' is not defined
foo.py:1: error: Cannot find module named 'builtins'
foo.py:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help)
foo.py:1: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521
Traceback (most recent call last):
  File "/home/me/.local/bin/mypy", line 11, in <module>
    sys.exit(console_entry())
  File "/home/me/.local/lib64/python3.4/site-packages/mypy/__main__.py", line 7, in console_entry
    main(None)
  File "/home/me/.local/lib64/python3.4/site-packages/mypy/main.py", line 50, in main
    res = type_check_only(sources, bin_dir, options)
  File "/home/me/.local/lib64/python3.4/site-packages/mypy/main.py", line 97, in type_check_only
    options=options)
  File "/home/me/.local/lib64/python3.4/site-packages/mypy/build.py", line 196, in build
    graph = dispatch(sources, manager)
  File "/home/me/.local/lib64/python3.4/site-packages/mypy/build.py", line 1801, in dispatch
    process_graph(graph, manager)
  File "/home/me/.local/lib64/python3.4/site-packages/mypy/build.py", line 2044, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/home/me/.local/lib64/python3.4/site-packages/mypy/build.py", line 2139, in process_stale_scc
    graph[id].semantic_analysis()
  File "/home/me/.local/lib64/python3.4/site-packages/mypy/build.py", line 1696, in semantic_analysis
    self.manager.semantic_analyzer.visit_file(self.tree, self.xpath, self.options, patches)
  File "/home/me/.local/lib64/python3.4/site-packages/mypy/semanal.py", line 295, in visit_file
    self.accept(d)
  File "/home/me/.local/lib64/python3.4/site-packages/mypy/semanal.py", line 3645, in accept
    node.accept(self)
  File "/home/me/.local/lib64/python3.4/site-packages/mypy/nodes.py", line 565, in accept
    return visitor.visit_func_def(self)
  File "/home/me/.local/lib64/python3.4/site-packages/mypy/semanal.py", line 418, in visit_func_def
    self.analyze_function(defn)
  File "/home/me/.local/lib64/python3.4/site-packages/mypy/semanal.py", line 598, in analyze_function
    defn.type = self.type_analyzer().visit_callable_type(defn.type, nested=False)
  File "/home/me/.local/lib64/python3.4/site-packages/mypy/typeanal.py", line 333, in visit_callable_type
    fallback=t.fallback or self.named_type('builtins.function'),
  File "/home/me/.local/lib64/python3.4/site-packages/mypy/typeanal.py", line 545, in named_type
    node = self.lookup_fqn_func(fully_qualified_name)
  File "/home/me/.local/lib64/python3.4/site-packages/mypy/semanal.py", line 3491, in lookup_fully_qualified
    n = self.modules[parts[0]]
KeyError: 'builtins'
foo.py:1: note: use --pdb to drop into pdb

I'm using python 3.4.5 under gentoo linux amd64. I had installed mypy using "pip3 install --user mypy" and my version of pip3 is "pip 9.0.1 from /usr/lib64/python3.4/site-packages (python 3.4)".

This was from a fresh install of mypy, but I then tried "pip3 install --user --upgrade mypy" which installed typing-3.6.2 but I still got the same error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions