8000 internal error using Enum and __new__ · Issue #1081 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

internal error using Enum and __new__ #1081

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
bcdarwin opened this issue Dec 17, 2015 · 4 comments
Closed

internal error using Enum and __new__ #1081

bcdarwin opened this issue Dec 17, 2015 · 4 comments
Labels
bug mypy got something wrong

Comments

@bcdarwin
Copy link

Making a list of types looks weird, but this was originally used to construct a typing.NamedTuple.

import typing
from typing import Tuple, Callable, Any, List
from enum import Enum

class MyEnum(Enum):
    def __new__(cls): pass

def F(fields: List[Callable[[Any], Any]]): pass

class SomeEnum(MyEnum):
    x = 1

F([SomeEnum])

produces:

Traceback (most recent call last):
  ...
  File "/home/bdarwin/.local/lib/python3.5/site-packages/mypy/types.py", line 346, in accept
    return visitor.visit_callable_type(self)
  File "/home/bdarwin/.local/lib/python3.5/site-packages/mypy/constraints.py", line 231, in visit_callable_type
    template.arg_types[i], cactual.arg_types[i],
IndexError: list index out of range

*** INTERNAL ERROR ***

foo.py:13: error: Internal error -- please report a bug at https://github.com/JukkaL/mypy/issues
The program exited via sys.exit(). Exit status: 1
@bcdarwin bcdarwin changed the title internal error using Enum, NamedTuple internal error using Enum and __new__ Dec 17, 2015
@gvanrossum
Copy link
Member
gvanrossum commented Dec 17, 2015 via email

@JukkaL JukkaL added the bug mypy got something wrong label Dec 18, 2015
@gvanrossum
Copy link
Member

I've removed a few red herrings from the repro; here's the smallest one I could find:

from typing import Any, Callable, List
def f(fields: List[Callable[[Any], Any]]): pass
class C: pass
f([C])

Some things I tried that went too far:

  • The argument type for f must be a List type
  • The Callable type must have an argument

The class's __init__ signature (here inherited from object) must not match the Callable given.

@gvanrossum
Copy link
Member

I think I've got a fix -- let me know if that solves your real-world case (I've already verified it solves the repro given here).

@bcdarwin
Copy link
Author

Yeah, that fixes it. Thanks!

@JukkaL JukkaL closed this as completed in 02e88c4 Dec 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants
0