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

pre-release v0.920 incorrectly identifies enum as final #11578

Closed
terencehonles opened this issue Nov 19, 2021 · 7 comments · Fixed by #11579
Closed

pre-release v0.920 incorrectly identifies enum as final #11578

terencehonles opened this issue Nov 19, 2021 · 7 comments · Fixed by #11579
Labels
bug mypy got something wrong

Comments

@terencehonles
Copy link
Contributor

Bug Report

Mypy incorrectly identifies an enum as final. This appears related to / caused by #11247.

To Reproduce

  1. create an enum with uninitialized annotated variables and a __new__ method
  2. extend the enum with the actual values for the enum

Expected Behavior

Mypy would not complain about the enum.

Actual Behavior

error: Cannot inherit from final class "TestEnum" [misc]

Your Environment

  • Mypy version used: https://github.com/mypyc/mypy_mypyc-wheels/releases/tag/v0.920%2Bdev.89bb94a636790fc969979a47d8cb88e33a22c17e
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
    [mypy]                                                                         
    allow_redefinition = true                                                      
    disable_error_code =                                                           
        override,                                                                  
        var-annotated                                                              
    mypy_path = types/                                                             
    plugins =                                                                      
        mypy_django_plugin.main                                            
        numpy.typing.mypy_plugin,                                                  
        mypy_drf_plugin.main                                                       
    pretty = true                                                                  
    show_error_codes = true                                                        
    show_error_context = true                                                      
    warn_redundant_casts = true                                                    
    warn_unused_ignores = true                                                     
    warn_unreachable = true
    
  • Python version used: 3.10.0
  • Operating system and version: N/A
@terencehonles terencehonles added the bug mypy got something wrong label Nov 19, 2021
@terencehonles
Copy link
Contributor Author

@sobolevn not sure if checking for initialized values would be trival to follow up with on your PR, but figured I'd ask you before looking into it myself.

@sobolevn
Copy link
Member

__new__ is not required for the repro.

This example raises:

from enum import Enum

class A(Enum):
    x: int
    y: int

class B(A):
    x = 1
    y = 2

print(B.x, B.y)  # Runtime print: B.x, B.y

Output:

out/ex.py:12: error: Cannot inherit from final class "A"
out/ex.py:13: error: Cannot override writable attribute "x" with a final one
out/ex.py:14: error: Cannot override writable attribute "y" with a final one

So, this is a bug I guess. I will try to solve this right now.

@sobolevn
Copy link
Member

The first one is quite easy to solve. But, I am not sure what to do with the 2nd and 3rd 🤔
Ideas?

@terencehonles
Copy link
Contributor Author

__new__ is not required for the repro.

Thanks for checking, I figured it didn't, but I wanted to make sure the example matched my particular code.

@achimnol
Copy link
Contributor

I'd like to reopen this issue, as mypy 0.930 release still gives me this error when inheriting a subclass (a custom StringSetFlag) of enum.Flag to define actual flags, which works fine in runtime.

@sobolevn
Copy link
Member

@achimnol please, open a new one with a repro example. I would be happy to fix it 🙂

@achimnol
Copy link
Contributor

@achimnol please, open a new one with a repro example. I would be happy to fix it 🙂

Just submitted a new issue as #11850.

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.

3 participants