Menu

Why doesn't PyCharm warn about this type mismatch?

Reading 0:00
15s threshold

I'm using PyCharm with Python 3.13 and trying to implement a generic CQRS pattern.

I explicitly specify int as the response type, but PyCharm doesn't report any error when the handler returns str.

``` from abc import ABC, abstractmethod from typing import Generic, TypeVar

TCommand = TypeVar("TCommand", bound="Command") TResponse = TypeVar("TResponse")

class Command(ABC, Generic[TResponse]): pass

class CommandHandler(ABC, Generic[TCommand, TResponse]): @abstractmethod async def handle(self, command: TCommand) -> TResponse: pass

class CreateUserCommand(Command[int]): pass

class CreateUserCommandHandler(CommandHandler[CreateUserCommand, int]): async def handle(self, command: CreateUserCommand) -> str: return "123"

```

Is this expected behavior, or am I missing something in my generic type definitions?