8000 Mypy crash in a function with match statement · Issue #13393 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Mypy crash in a function with match statement #13393

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
tianyicui-tsy opened this issue Aug 12, 2022 · 2 comments
Closed

Mypy crash in a function with match statement #13393

tianyicui-tsy opened this issue Aug 12, 2022 · 2 comments
Labels
crash topic-match-statement Python 3.10's match statement

Comments

@tianyicui-tsy
Copy link

Crash Report

mypy crashed in a function of mine that uses match statement.

Traceback

$ mypy a.py --show-traceback
a.py:7: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.980+dev.92420469fddfb6b96b1e66ed8ab02ace550bc01c
Traceback (most recent call last):
  File "/path/redacted/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/path/redacted/lib/python3.10/site-packages/mypy/__main__.py", line 12, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "/path/redacted/lib/python3.10/site-packages/mypy/main.py", line 94, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "/path/redacted/lib/python3.10/site-packages/mypy/main.py", line 173, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/path/redacted/lib/python3.10/site-packages/mypy/build.py", line 189, in build
    result = _build(
  File "/path/redacted/lib/python3.10/site-packages/mypy/build.py", line 273, in _build
    graph = dispatch(sources, manager, stdout)
  File "/path/redacted/lib/python3.10/site-packages/mypy/build.py", line 2880, in dispatch
    process_graph(graph, manager)
  File "/path/redacted/lib/python3.10/site-packages/mypy/build.py", line 3264, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/path/redacted/lib/python3.10/site-packages/mypy/build.py", line 3365, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/path/redacted/lib/python3.10/site-packages/mypy/build.py", line 2308, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/path/redacted/lib/python3.10/site-packages/mypy/checker.py", line 460, in check_first_pass
    self.accept(d)
  File "/path/redacted/lib/python3.10/site-packages/mypy/checker.py", line 566, in accept
    stmt.accept(self)
  File "/path/redacted/lib/python3.10/site-packages/mypy/nodes.py", line 811, in accept
    return visitor.visit_func_def(self)
  File "/path/redacted/lib/python3.10/site-packages/mypy/checker.py", line 930, in visit_func_def
    self._visit_func_def(defn)
  File "/path/redacted/lib/python3.10/site-packages/mypy/checker.py", line 934, in _visit_func_def
    self.check_func_item(defn, name=defn.name)
  File "/path/redacted/lib/python3.10/site-packages/mypy/checker.py", line 1003, in check_func_item
    self.check_func_def(defn, typ, name)
  File "/path/redacted/lib/python3.10/site-packages/mypy/checker.py", line 1187, in check_func_def
    self.accept(item.body)
  File "/path/redacted/lib/python3.10/site-packages/mypy/checker.py", line 566, in accept
    stmt.accept(self)
  File "/path/redacted/lib/python3.10/site-packages/mypy/nodes.py", line 1201, in accept
    return visitor.visit_block(self)
  File "/path/redacted/lib/python3.10/site-packages/mypy/checker.py", line 2379, in visit_block
    self.accept(s)
  File "/path/redacted/lib/python3.10/site-packages/mypy/checker.py", line 566, in accept
    stmt.accept(self)
  File "/path/redacted/lib/python3.10/site-packages/mypy/nodes.py", line 1556, in accept
    return visitor.visit_match_stmt(self)
  File "/path/redacted/lib/python3.10/site-packages/mypy/checker.py", line 4433, in visit_match_stmt
    pattern_types = [self.pattern_checker.accept(p, subject_type) for p in s.patterns]
  File "/path/redacted/lib/python3.10/site-packages/mypy/checker.py", line 4433, in <listcomp>
    pattern_types = [self.pattern_checker.accept(p, subject_type) for p in s.patterns]
  File "/path/redacted/lib/python3.10/site-packages/mypy/checkpattern.py", line 119, in accept
    result = o.accept(self)
  File "/path/redacted/lib/python3.10/site-packages/mypy/patterns.py", line 90, in accept
    return visitor.visit_sequence_pattern(self)
  File "/path/redacted/lib/python3.10/site-packages/mypy/checkpattern.py", line 307, in visit_sequence_pattern
    new_type = self.construct_sequence_child(current_type, new_inner_type)
  File "/path/redacted/lib/python3.10/site-packages/mypy/checkpattern.py", line 651, in construct_sequence_child
    types = [
  File "/path/redacted/lib/python3.10/site-packages/mypy/checkpattern.py", line 652, in <listcomp>
    self.construct_sequence_child(item, inner_type)
  File "/path/redacted/lib/python3.10/site-packages/mypy/checkpattern.py", line 660, in construct_sequence_child
    assert isinstance(proper_type, Instance)
AssertionError: 
a.py:7: : note: use --pdb to drop into pdb

To Reproduce

Use mypy master and Python 3.10.4 to check the following file

from typing import Tuple, TypeAlias

MyType: TypeAlias = str | Tuple[str, str] | float


def test_fn(input: MyType) -> float:
    match input:
        case str():
            return float(input)
        case str(), str():
            a, b = input
            return float(a) - float(b)
        case float():
            return input
        case _:
            raise ValueError("Unexpected input type")

Your Environment

  • Mypy version used: 0.980+dev.92420469fddfb6b96b1e66ed8ab02ace550bc01c
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.10.4
@AlexWaygood AlexWaygood added the topic-match-statement Python 3.10's match statement label Aug 12, 2022
@AlexWaygood
Copy link
Member

Duplicate of #12533

@AlexWaygood AlexWaygood marked this as a duplicate of #12533 Aug 12, 2022
@AlexWaygood AlexWaygood closed this as not planned Won't fix, can't repro, duplicate, stale Aug 12, 2022
@hauntsaninja
Copy link
Collaborator

Btw, is the project you encountered this on open source? If so, I can add it to https://github.com/hauntsaninja/mypy_primer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash topic-match-statement Python 3.10's match statement
Projects
None yet
Development

No branches or pull requests

3 participants
0