Skip to content

Final classes and member functions #286

Closed
python/mypy
#5522
@dgoldstein0

Description

@dgoldstein0

In some languages (e.g. java) it's possible to declare a class as final so that it can't be subclassed; similarly, it's possible to declare functions as final so that they can't be overridden by sublclasses. It would be great if typing could support this - so that classes could be annotated as final or their functions as final, and then tools like mypy could enforce it.

E.g.

@final
class Foo(object):
  pass

# type error
class Bar(Foo):
  pass

(reposting from python/mypy#2032)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions