Skip to content

Crash with invalid NewType and union #4381

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
JukkaL opened this issue Dec 18, 2017 · 1 comment
Closed

Crash with invalid NewType and union #4381

JukkaL opened this issue Dec 18, 2017 · 1 comment

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Dec 18, 2017

Type checking the following program causes a crash (simplified from a real-world example):

from typing import List, NewType, Union

N = NewType('N', XXX)

x: List[Union[N, int]]

Here's the traceback:

$ mypy --show-traceback t/rt.py
t/rt.py:3: error: Argument 2 to NewType(...) must be subclassable (got "Any")
t/rt.py:3: error: Name 'XXX' is not defined
t/rt.py:1: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.560-dev-fcd91d00253449ea2571f1ffdcb5bb587ab7d8a5
Traceback (most recent call last):
  File "/Users/jukka/src/mypy/scripts/mypy", line 6, in <module>
    main(__file__)
  File "/Users/jukka/src/mypy/mypy/main.py", line 66, in main
    res = type_check_only(sources, bin_dir, options)
  File "/Users/jukka/src/mypy/mypy/main.py", line 119, in type_check_only
    options=options)
  File "/Users/jukka/src/mypy/mypy/build.py", line 218, in build
    graph = dispatch(sources, manager)
  File "/Users/jukka/src/mypy/mypy/build.py", line 2000, in dispatch
    process_graph(graph, manager)
  File "/Users/jukka/src/mypy/mypy/build.py", line 2304, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/Users/jukka/src/mypy/mypy/build.py", line 2474, in process_stale_scc
    graph[id].semantic_analysis_pass_three()
  File "/Users/jukka/src/mypy/mypy/build.py", line 1866, in semantic_analysis_pass_three
    self.options, patches)
  File "/Users/jukka/src/mypy/mypy/semanal_pass3.py", line 61, in visit_file
    self.accept(file_node)
  File "/Users/jukka/src/mypy/mypy/semanal_pass3.py", line 79, in accept
    node.accept(self)
  File "/Users/jukka/src/mypy/mypy/nodes.py", line 228, in accept
    return visitor.visit_mypy_file(self)
  File "/Users/jukka/src/mypy/mypy/traverser.py", line 30, in visit_mypy_file
    d.accept(self)
  File "/Users/jukka/src/mypy/mypy/nodes.py", line 805, in accept
    return visitor.visit_assignment_stmt(self)
  File "/Users/jukka/src/mypy/mypy/semanal_pass3.py", line 200, in visit_assignment_stmt
    self.analyze(s.type, s)
  File "/Users/jukka/src/mypy/mypy/semanal_pass3.py", line 348, in analyze
    type.accept(analyzer)
  File "/Users/jukka/src/mypy/mypy/types.py", line 475, in accept
    return visitor.visit_instance(self)
  File "/Users/jukka/src/mypy/mypy/typeanal.py", line 727, in visit_instance
    if not is_subtype(arg, bound):
  File "/Users/jukka/src/mypy/mypy/subtypes.py", line 83, in is_subtype
    ignore_declared_variance=ignore_declared_variance))
  File "/Users/jukka/src/mypy/mypy/types.py", line 1230, in accept
    return visitor.visit_union_type(self)
  File "/Users/jukka/src/mypy/mypy/subtypes.py", line 312, in visit_union_type
    for item in left.items)
  File "/Users/jukka/src/mypy/mypy/subtypes.py", line 312, in <genexpr>
    for item in left.items)
  File "/Users/jukka/src/mypy/mypy/subtypes.py", line 83, in is_subtype
    ignore_declared_variance=ignore_declared_variance))
  File "/Users/jukka/src/mypy/mypy/types.py", line 1415, in accept
    return visitor.visit_forwardref_type(self)
  File "/Users/jukka/src/mypy/mypy/types.py", line 1500, in visit_forwardref_type
    raise RuntimeError('Internal error: unresolved forward reference')
RuntimeError: Internal error: unresolved forward reference
t/rt.py:1: : note: use --pdb to drop into pdb
@ilevkivskyi
Copy link
Member

This is a duplicate of #4200 (see also #3977 for underlying cause, also #4200 (comment) and #4200 (comment) for solution strategy.)

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

No branches or pull requests

2 participants