Skip to content
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

Internal error with namedtuple+classmethod #3317

Closed
Daenyth opened this issue May 4, 2017 · 5 comments
Closed

Internal error with namedtuple+classmethod #3317

Daenyth opened this issue May 4, 2017 · 5 comments

Comments

@Daenyth
Copy link

Daenyth commented May 4, 2017

Running off the latest master.

from typing import *

class Bar(NamedTuple):
    x: str

    @classmethod
    def new(cls, f: str) -> 'Bar':
        return Bar(x=f)
[mypy]
python_version = 3.6

check_untyped_defs = True
disallow_untyped_calls = True
follow_imports = True
incremental = True
strict_optional = True
warn_no_return = True
warn_return_any = True
warn_unused_ignores = True
foo.py:6: error: Invalid statement in NamedTuple definition; expected "field_name: field_type"
foo.py:6: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.510-dev-09e7b124b82dae1207d9eac6805b64a98290015c

This might be fixed by #3081? I'm not sure how to install that to test

Stack trace is here
Traceback (most recent call last):
  File "/Users/daenyth/Curata/observer/.tox/mypy/bin/mypy", line 6, in <module>
    main(__file__)
  File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/main.py", line 46, in main
    res = type_check_only(sources, bin_dir, options)
  File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/main.py", line 93, in type_check_only
    options=options)
  File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/build.py", line 188, in build
    graph = dispatch(sources, manager)
  File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/build.py", line 1595, in dispatch
    process_graph(graph, manager)
  File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/build.py", line 1838, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/build.py", line 1937, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/build.py", line 1510, in type_check_first_pass
    self.type_checker.check_first_pass()
  File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/checker.py", line 177, in check_first_pass
    self.accept(d)
  File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/checker.py", line 264, in accept
    stmt.accept(self)
  File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/nodes.py", line 749, in accept
    return visitor.visit_class_def(self)
  File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/checker.py", line 1080, in visit_class_def
    self.accept(defn.defs)
  File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/checker.py", line 264, in accept
    stmt.accept(self)
  File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/nodes.py", line 810, in accept
    return visitor.visit_block(self)
  File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/checker.py", line 1173, in visit_block
    self.accept(s)
  File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/checker.py", line 264, in accept
    stmt.accept(self)
  File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/nodes.py", line 631, in accept
    return visitor.visit_decorator(self)
  File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/checker.py", line 2213, in visit_decorator
    e.func.accept(self)
  File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/nodes.py", line 564, in accept
    return visitor.visit_func_def(self)
  File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/checker.py", line 513, in visit_func_def
    self.check_method_override(defn)
  File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/checker.py", line 945, in check_method_override
    for base in defn.info.mro[1:]:
TypeError: 'NoneType' object is not subscriptable
@Daenyth Daenyth changed the title Internal error with union+namedtuple+classmethod Internal error with namedtuple+classmethod May 4, 2017
@Daenyth
Copy link
Author

Daenyth commented May 4, 2017

I figured out how to install it (deps line in tox needs git+git://github.com/JelleZijlstra/mypy.git@ntmethods)

#3081 does fix the crash

I do still get foo.py:6: error: Invalid statement in NamedTuple definition; expected "field_name: field_type [= default]" though

@Daenyth Daenyth closed this as completed May 4, 2017
@JukkaL
Copy link
Collaborator

JukkaL commented May 4, 2017

Keeping this open until until #3081 has been merged.

@JukkaL JukkaL reopened this May 4, 2017
@ilevkivskyi
Copy link
Member

@Daenyth By the way, do you still see the crash on master without incremental?

@JukkaL
Copy link
Collaborator

JukkaL commented May 4, 2017

I can repro without a config file and without incremental on master. Also verified that this doesn't happen on 0.501 so this is a regression and I'd like to get this fixed before release. Since we are in feature freeze, I'd rather have a specific fix for this issue instead of landing #3081. Anybody want to look at extracting the fix for this from #3081 (or implementing an independent fix)?

^^ @JelleZijlstra @ilevkivskyi

@JelleZijlstra
Copy link
Member

JelleZijlstra commented May 4, 2017 via email

JelleZijlstra added a commit to JelleZijlstra/mypy that referenced this issue May 4, 2017
Really hacky but this should work for now. I think the bug
was introduced when we added support for NamedTuple
classmethods.

Fixes python#3317
JukkaL pushed a commit that referenced this issue May 4, 2017
Really hacky but this should work for now. I think the bug
was introduced when we added support for NamedTuple
classmethods.

Fixes #3317
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

5 participants