Skip to content

Protocol with nested class #15835

Open
Open
@finswimmer

Description

@finswimmer

Bug Report

Hey,

I don't know if this a bug report, feature request or simply a question about how to do it right 😄

For proper typing I need to overload the type annotation based on the argument types. One type involved is a Protocol. Everything works as expected as long as the Protocol consists of properties or method. But as soon as I'm looking for a class within the Protocol, mypy cannot find an overload variant. (See below)

(A clear and concise description of what the bug is.)

To Reproduce

This works:

https://mypy-play.net/?mypy=latest&python=3.11&gist=d750eefc830c2080d989a7437ca518b6

This fails:

https://mypy-play.net/?mypy=latest&python=3.11&gist=0e424fbd22d314764a0d13ac9f8fe0b5

main.py:40: error: No overload variant of "create" of "Client" matches argument type "Content"  [call-overload]
main.py:40: note: Possible overload variants:
main.py:40: note:     def [_SupportsConfig <: SupportsConfig] create(self, content: _SupportsConfig) -> _SupportsConfig
main.py:40: note:     def [_SupportsConfig <: SupportsConfig] create(self, content: _SupportsConfig, result_class: None) -> _SupportsConfig
main.py:40: note:     def [_SupportsConfig <: SupportsConfig, _T] create(self, content: _SupportsConfig, result_class: type[_T]) -> _T

So, do I have to achieve my goal?

fin swimmer

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions