Skip to content

Rework typing in the repo #164

Open
Open
@mkmkme

Description

@mkmkme

As was pointed in #162, the typing problems go quite deep and will likely require some refactoring.

The biggest issue is the fact that sync and async clients inherit from the same class, which causes issues in type system.

For instance, this code:

from typing import *

class Parent:
    def set(self) -> int:
        return 1
        
class Child(Parent):
    async def set(self) -> int:
        return 1

raises this mypy error:

main.py:8: error: Return type "Coroutine[Any, Any, int]" of "set" incompatible with return type "int" in supertype "Parent"  [override]

Attempting to have a union there won't help either. That is, this code

from typing import *

class Parent:
    def set(self) -> int | Coroutine[Any, Any, int]:
        return 1
        
class Child(Parent):
    async def set(self) -> int | Coroutine[Any, Any, int]:
        return 1

causes this error

main.py:8: error: Return type "Coroutine[Any, Any, int | Coroutine[Any, Any, int]]" of "set" incompatible with return type "int | Coroutine[Any, Any, int]" in supertype "Parent"  [override]

There should be a way to fix this without completely reworking the class hierarchy in the repo. This should be investigated.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions