UnitTestBot / UTBotJava

Automated unit test generation and precise code analysis for Java
Apache License 2.0
136 stars 43 forks source link

One more case in `utbot-python-types` subtype checker #2688

Closed tochilinak closed 1 year ago

tochilinak commented 1 year ago

Description

Added support for such protocols:

class SupportsCall(Protocol):
    def __call__(self, *args, **kwargs):
        ...

class HasF(Protocol):
    f: SupportsCall

class SupportsSpecificCall(Protocol):
    def __call__(self, *args, **kwargs) -> HasF:
        ...

class HasSpecificF(Protocol):
    f: SupportsSpecificCall

Example of class that supports HasF but not HasSpecificF:

class S:
    def f(self, x: Union[int, str]) -> collections.Counter:
        return collections.Counter([x])

Example of class that supports HasSpecificF:

class RImpl:
    def f(self) -> 'RImpl':
        return self

How to test

Automated tests

Self-check list

Check off the item if the statement is true. Hint: [x] is a marked item.

Please do not delete the list or its items.