Skip to content

Consider allowing @final methods in Protocols #13310

Open
@tmke8

Description

@tmke8

Feature

Allow this:

from typing import Protocol, final

class Sized(Protocol):
    len: int
    @final
    def __len__(self) -> int:
        return self.len

Pitch

I get that this is a bit unusual, but I don’t really see any harm that could come from this (as an aside, pyright allows it). My use case is that I’m using Protocols for mixins, and sometimes I want to make sure my mixed-in methods don’t get overwritten.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions