8000 INTERNAL ERROR when defining method argument type as class member in @runtime_checkable Protocol · Issue #10577 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

INTERNAL ERROR when defining method argument type as class member in @runtime_checkable Protocol #10577

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
posita opened this issue Jun 3, 2021 · 0 comments · Fixed by #13526

Comments

@posita
Copy link
Contributor
posita commented Jun 3, 2021

Possibly related to: #9908, #10357, #10521, #10522.

Crash Report

# $ cat mypy-bug.py
from typing import Protocol, Union
from typing_extensions import runtime_checkable
from operator import add as op_add

class Foo: pass

# FooAbleOperandT = Union[int, float, Foo, "FooAbleT"]  # <- this will work

@runtime_checkable
class FooAbleT(Protocol):
    FooAbleOperandT = Union[int, float, Foo, "FooAbleT"]  # <- this won't
    def __add__(self, other: FooAbleOperandT) -> Foo:
        return op_add(self.foo(), other)
    def __radd__(self, other: Union[int, float]) -> Foo:  # <- chokes here
        return op_add(other, self.foo())
    def foo(self) -> Foo: ...

Traceback

mypy-bug.py:14: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.rtfd.io/en/latest/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.812
Traceback (most recent call last):
  File "mypy/checker.py", line 401, in accept
  File "mypy/nodes.py", line 687, in accept
  File "mypy/checker.py", line 726, in visit_func_def
  File "mypy/checker.py", line 730, in _visit_func_def
  File "mypy/checker.py", line 792, in check_func_item
  File "mypy/checker.py", line 850, in check_func_def
  File "mypy/checker.py", line 1211, in check_reverse_op_method
  File "mypy/checker.py", line 1263, in check_overlapping_op_methods
  File "mypy/checker.py", line 1322, in is_unsafe_overlapping_op
  File "mypy/checker.py", line 5300, in is_unsafe_overlapping_overload_signatures
  File "mypy/subtypes.py", line 916, in is_callable_compatible
  File "mypy/subtypes.py", line 1040, in are_args_compatible
  File "mypy/subtypes.py", line 1045, in new_is_compat
  File "mypy/checker.py", line 5786, in is_overlapping_types_no_promote
  File "mypy/meet.py", line 184, in is_overlapping_types
  File "mypy/subtypes.py", line 1156, in is_proper_subtype
  File "mypy/subtypes.py", line 1177, in _is_proper_subtype
  File "mypy/types.py", line 833, in accept
  File "mypy/subtypes.py", line 1273, in visit_instance
  File "mypy/subtypes.py", line 539, in is_protocol_implementation
AssertionError:
mypy-bug.py:14: : note: use --pdb to drop into pdb
@posita posita added the crash label Jun 3, 2021
posita added a commit to posita/dyce that referenced this issue Jun 6, 2021
- Refactor `HAbleT` and move binary operations to `HAbleBinOpsMixin` and include them in
  docs
- Refactor types out of classes (see python/mypy#10577)
- Remove largly unused `relative` parameter from `H.data_xy`
- Better tolerate `Integral`s in addition to `int`s to ease use with (e.g.) SageMath
- Fix Risus graphic and other doc tweaks
posita added a commit to posita/dyce that referenced this issue Jun 6, 2021
- Refactor `HAbleT` and move binary operations to `HAbleBinOpsMixin` and include them in
  docs
- Refactor types out of classes (see python/mypy#10577)
- Remove largly unused `relative` parameter from `H.data_xy`
- Better tolerate `Integral`s in addition to `int`s to ease use with (e.g.) SageMath
- Fix Risus graphic and other doc tweaks
posita added a commit to posita/dyce that referenced this issue Jun 6, 2021
- Refactor `HAbleT` and move binary operations to `HAbleBinOpsMixin` and include them in
  docs
- Refactor types out of classes (see python/mypy#10577)
- Remove largly unused `relative` parameter from `H.data_xy`
- Better tolerate `Integral`s in addition to `int`s to ease use with (e.g.) SageMath
- Fix Risus graphic and other doc tweaks
posita added a commit to posita/dyce that referenced this issue Jun 6, 2021
- Refactor `HAbleT` and move binary operations to `HAbleBinOpsMixin` and include them in
  docs
- Refactor types out of classes (see python/mypy#10577)
- Remove largly unused `relative` parameter from `H.data_xy`
- Better tolerate `Integral`s in addition to `int`s to ease use with (e.g.) SageMath
- Fix Risus graphic and other doc tweaks
posita added a commit to posita/dyce that referenced this issue Jun 6, 2021
- Refactor `HAbleT` and move binary operations to `HAbleBinOpsMixin` and include them in
  docs
- Refactor types out of classes (see python/mypy#10577)
- Refactor backward-compatible `gcd` implementation into `symmetries`
- Remove largly unused `relative` parameter from `H.data_xy`
- Better tolerate `Integral`s in addition to `int`s to ease use with (e.g.) SageMath
- Fix Risus graphic and other doc tweaks
posita added a commit to posita/dyce that referenced this issue Jun 6, 2021
- Refactor `HAbleT` and move binary operations to `HAbleBinOpsMixin` and include them in
  docs
- Refactor types out of classes (see python/mypy#10577)
- Refactor backward-compatible `gcd` implementation into `symmetries`
- Remove largly unused `relative` parameter from `H.data_xy`
- Better tolerate `Integral`s in addition to `int`s to ease use with (e.g.) SageMath
- Fix Risus graphic and other doc tweaks
posita added a commit to posita/dyce that referenced this issue Jun 7, 2021
- Refactor `HAbleT` and move binary operations to `HAbleBinOpsMixin` and include them in
  docs
- Refactor types out of classes (see python/mypy#10577)
- Refactor backward-compatible `gcd` implementation into `symmetries`
- Remove largly unused `relative` parameter from `H.data_xy`
- Better tolerate `Integral`s in addition to `int`s to ease use with (e.g.) SageMath
- Fix Risus graphic and other doc tweaks
posita added a commit to posita/dyce that referenced this issue Jun 7, 2021
- Fix addition/substraction operations to work more sanely w/ `H({})`
- Refactor `HAbleT` and move binary operations to `HAbleBinOpsMixin` and include them in
  docs
- Refactor types out of classes (see python/mypy#10577)
- Refactor backward-compatible `gcd` implementation into `symmetries`
- Remove largly unused `relative` parameter from `H.data_xy`
- Better tolerate `Integral`s in addition to `int`s to ease use with (e.g.) SageMath
- Fix Risus graphic and other doc tweaks
posita added a commit to posita/dyce that referenced this issue Jun 7, 2021
- Added `H.__hash__`
- Fix addition/substraction operations to work more sanely w/ `H({})`
- Refactor `HAbleT` and move binary operations to `HAbleBinOpsMixin` and include them in
  docs
- Refactor types out of classes (see python/mypy#10577)
- Refactor backward-compatible `gcd` implementation into `symmetries`
- Remove largly unused `relative` parameter from `H.data_xy`
- Better tolerate `Integral`s in addition to `int`s to ease use with (e.g.) SageMath
- Fix Risus graphic and other doc tweaks
posita added a commit to posita/dyce that referenced this issue Jun 7, 2021
- Added `H.__hash__`
- Fix addition/substraction operations to work more sanely w/ `H({})`
- Refactor `HAbleT` and move binary operations to `HAbleBinOpsMixin` and include them in
  docs
- Refactor types out of classes (see python/mypy#10577)
- Refactor backward-compatible `gcd` implementation into `symmetries`
- Remove largly unused `relative` parameter from `H.data_xy`
- Better tolerate `Integral`s in addition to `int`s to ease use with (e.g.) SageMath
- Fix Risus graphic and other doc tweaks
@AlexWaygood AlexWaygood added the topic-type-alias TypeAlias and other type alias issues label Apr 21, 2022
ilevkivskyi added a commit that referenced this issue Aug 26, 2022
Fixes #6801
Fixes #10577
Fixes #12642
Fixes #12337
Fixes #10639 
Fixes #13390 

All these crashes are in a sense duplicates of each other. Fix is trivial, except I decided to ban type aliases in protocol bodies. Already in the examples in issues, I have found two cases where people wrote `foo = list[str]`, where they clearly wanted `foo: list[str]`. This can cause hard to spot false negatives.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
0