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

Callable dataclass member flags #8738

Closed
JuliusDegesys opened this issue Apr 28, 2020 · 4 comments
Closed

Callable dataclass member flags #8738

JuliusDegesys opened this issue Apr 28, 2020 · 4 comments
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal

Comments

@JuliusDegesys
Copy link

JuliusDegesys commented Apr 28, 2020

  • Are you reporting a bug, or opening a feature request?
    Reporting a bug

  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.

from typing import *
from dataclasses import dataclass

class Foo:
    pass

FooProducer = Callable[..., Foo]

@dataclass(frozen=True)
class Bar:
    wrapped: FooProducer

def unpack_bar(x: Bar) -> FooProducer:
    return x.wrapped # This line flags

class Baz:
    def __init__(self, wrapped: FooProducer) -> None:
        self.wrapped = wrapped

def unpack_baz(x: Baz) -> FooProducer:
    return x.wrapped # This line is ok
  • What is the actual behavior/output?
    src/debug_mypy.py:18: error: Incompatible return value type (got "Foo", expected "Callable[..., Foo]")
    Found 1 error in 1 file (checked 1 source file)

  • What is the behavior/output you expect?
    No error.

  • What are the versions of mypy and Python you are using?

$ mypy --version
mypy 0.770

$ python --version
Python 3.8.2

Do you see the same issue after installing mypy from Git master?
Yes

$ mypy src/debug_mypy.py 
src/debug_mypy.py:18: error: Incompatible return value type (got "Foo", expected "Callable[..., Foo]")
Found 1 error in 1 file (checked 1 source file)

$ mypy --version
mypy 0.770+dev.2c8d76efee7f6419654f0a913d29d9f4edb49574
  • What are the mypy flags you are using? (For example --strict-optional)
    None

  • If mypy crashed with a traceback, please paste
    the full traceback below.

@JelleZijlstra
Copy link
Member

This feels similar to #5485 (previously reported dupes include #8618), but the error message sounds a bit different.

@JukkaL
Copy link
Collaborator

JukkaL commented May 1, 2020

Let's keep this open, as this may be slightly different from previously reported issues.

@JukkaL JukkaL added bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal labels May 1, 2020
@Akuli
Copy link
Contributor

Akuli commented Oct 25, 2021

No longer errors on master:

(env310) akuli@akuli-desktop:~/mypy$ cat >a.py
from typing import *
from dataclasses import dataclass

class Foo:
    pass

FooProducer = Callable[..., Foo]

@dataclass(frozen=True)
class Bar:
    wrapped: FooProducer

def unpack_bar(x: Bar) -> FooProducer:
    return x.wrapped # This line flags

class Baz:
    def __init__(self, wrapped: FooProducer) -> None:
        self.wrapped = wrapped

def unpack_baz(x: Baz) -> FooProducer:
    return x.wrapped # This line is ok


(env310) akuli@akuli-desktop:~/mypy$ python3 -m mypy a.py
Success: no issues found in 1 source file

@ethanhs
Copy link
Collaborator

ethanhs commented Oct 25, 2021

This does seem to be fixed in master.

@ethanhs ethanhs closed this as completed Oct 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal
Projects
None yet
Development

No branches or pull requests

5 participants