Skip to content

Feature request: Disallow final classes from having abstract methods or properties #8316

Closed
@lazytype

Description

@lazytype

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions