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

Missing return statement error using enums and match #15878

Closed
bradleyneumaier opened this issue Aug 15, 2023 · 2 comments · Fixed by #15882
Closed

Missing return statement error using enums and match #15878

bradleyneumaier opened this issue Aug 15, 2023 · 2 comments · Fixed by #15882
Labels
bug mypy got something wrong

Comments

@bradleyneumaier
Copy link

Bug Report

I have an exhaustive match block with return statements for each case, but mypy flags it as a missing return error: error: Missing return statement [return]

To Reproduce

from dataclasses import dataclass
from datetime import datetime
import enum
from typing import assert_never


class MyEnum(enum.Enum):
    a = "a"
    b = "b"
    c = "c"
    

@dataclass
class MyClass:
    expires_at: datetime | None
    
    @property
    def status(self) -> MyEnum:
        match self.expires_at:
            case None:
                return MyEnum.a
            case time if time <= datetime.now():
                return MyEnum.b
            case _:
                return MyEnum.c

https://mypy-play.net/?mypy=1.5.0&python=3.11&gist=122ad20737777670f775c802a36251d9

Expected Behavior

No error raised

Actual Behavior

error: Missing return statement [return] is raised

Your Environment

  • Mypy version used: 1.5.0
  • Python version used: 3.11
@hauntsaninja
Copy link
Collaborator

I merged the fix, is your project open source? If so, we can add it to mypy_primer

@bradleyneumaier
Copy link
Author

Awesome, thanks for the quick fix! Project is not open source unfortunately

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

Successfully merging a pull request may close this issue.

2 participants