Skip to content

False Negative when Enforcing Positional Arguments in regards to Protocols #637

@max-muoto

Description

@max-muoto

Summary

Wasn't able to find this, but apologies if it's already been brought up in another issue, but this is more or less a rehash of python/mypy#17421 for Ty.

In effect Ty doesn't raise a warning if you pass in an class implementation that enforces positional arguments on a method, for a protocol that does not.

Take this example, which should raise a warning but doesn't:

from typing import Protocol


class Readable(Protocol):
    def read(self, n: int = -1) -> bytes: ...

class ActualReadable:
    def read(self, n: int = -1, /) -> bytes:
        return b""


def foo(readable: Readable) -> None:
    readable.read(n=1)


foo(ActualReadable())

This can lead to a runtime error if the protocol implementation is called using a key-word argument.

Ty Playground

If this is simply the result of support for protocols not being finalized, feel free to close this.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions