Skip to content

Annotate types for Actor and Message#512

Merged
Bogdanp merged 2 commits intoBogdanp:masterfrom
orsinium-forks:mypy
Nov 26, 2022
Merged

Annotate types for Actor and Message#512
Bogdanp merged 2 commits intoBogdanp:masterfrom
orsinium-forks:mypy

Conversation

@orsinium
Copy link
Contributor

@orsinium orsinium commented Nov 25, 2022

  1. Fix existing type violations reported by mypy.
  2. Annotate types for Actor, actor, and Message
  3. Use TypeVar with Generic to propagate the return type of the function. For example, if you wrap a function that returns str, then mypy will know that calling Actor instance also returns str.

Something that can be improved later:

  1. Message is a namedtuple, and so cannot inherit from Generic. It can be solved by using a dataclass instead.
  2. Types for arguments of the function can be typed with Parameter Specification Variables, but for that, you'll need typing-extensions the good news is that it can be static-only dependency by putting it inside of if TYPE_CHECKING. But I didn't want to complicate this PR too much.

@Bogdanp Bogdanp merged commit a231ba9 into Bogdanp:master Nov 26, 2022
@Bogdanp
Copy link
Owner

Bogdanp commented Nov 26, 2022

Thanks!

@orsinium orsinium deleted the mypy branch November 26, 2022 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants