You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, mypy checks whether a class is abstract when it's instantiated. For classes with the @final decorator, it would make sense for there to be a typing error if they define any abstract methods or properties, since those could never be implemented.
It would also make sense for classes that explicitly have the ABCMeta metaclass and also have the @final decorator to be a typing error if the class contains any instance methods or properties, since there could never be an instance created to call them with.
Note that abstract final classes are an idiom that is sometimes used in Java to define a class that is just a grouping of static methods, but I believe that's mostly a result of Java not having modules and top-level functions. In Python, one could organize top-level functions and group them with a module. This could be an argument to disallow a class to have both @final and ABCMeta all-together.
The text was updated successfully, but these errors were encountered:
lazytype
changed the title
Disallow final classes from having abstract methods or properties
Feature request: Disallow final classes from having abstract methods or properties
Jan 23, 2020
I like this idea. It is also easy to implement, one would just need to add a check at the end of calculate_class_abstract_status() giving an error if the class is final but the lost of abstract attributes is non-empty.
Currently, mypy checks whether a class is abstract when it's instantiated. For classes with the
@final
decorator, it would make sense for there to be a typing error if they define any abstract methods or properties, since those could never be implemented.It would also make sense for classes that explicitly have the
ABCMeta
metaclass and also have the@final
decorator to be a typing error if the class contains any instance methods or properties, since there could never be an instance created to call them with.Note that
abstract final
classes are an idiom that is sometimes used in Java to define a class that is just a grouping of static methods, but I believe that's mostly a result of Java not having modules and top-level functions. In Python, one could organize top-level functions and group them with a module. This could be an argument to disallow a class to have both@final
andABCMeta
all-together.The text was updated successfully, but these errors were encountered: