microsoft / autogen

A programming framework for agentic AI. Discord: https://aka.ms/autogen-dc. Roadmap: https://aka.ms/autogen-roadmap
https://microsoft.github.io/autogen/
Creative Commons Attribution 4.0 International
27.91k stars 4.07k forks source link

[Feature Request]: fixing type annotations #1462

Open davorrunje opened 5 months ago

davorrunje commented 5 months ago

Is your feature request related to a problem? Please describe.

When extending the framework, developers use typing information from existing code. However, this information is sometimes incomplete (e.g. parameters having type annotations List without specifying if is it a list of strings or dictionaries) or sometimes even wrong (functions change over time and sometimes type annotations are not properly updated). It also makes testing difficult because it is not always clear which cases need to be checked.

A good way to enforce correctness of the type annotations would be to ensure mypy check passes. Currently, running it on autogen with the configuration below yields over 1000 errors.

Describe the solution you'd like

  1. Add the following configuration to pyproject.toml:
    
    [tool.mypy]

strict = true python_version = "3.8" ignore_missing_imports = true install_types = true non_interactive = true plugins = [ "pydantic.mypy" ]

makes it easer to incrementally fix file by file

follow_imports = "silent"

from https://blog.wolt.com/engineering/2021/09/30/professional-grade-mypy-configuration/

disallow_untyped_defs = true no_implicit_optional = true check_untyped_defs = true warn_return_any = true show_error_codes = true warn_unused_ignores = true

disallow_incomplete_defs = true disallow_untyped_decorators = true disallow_any_unimported = true



2. Fix type annotations in related groups of changed files in multiple PRs.

### Additional context

_No response_
ekzhu commented 5 months ago

Currently, running it on autogen with the configuration below yields over 1000 errors.

This is a lot! Do you think there is a way for us to fix all these errors incrementally?

davorrunje commented 5 months ago

@ekzhu yes, I would go file by file per PR (or a few related ones). I am actually quite fast in such things, I could finish it all in a week or so.

jackgerrits commented 4 months ago

I have noticed that mypy config your PRs @davorrunje. Before I saw this issue I went ahead and opened a PR to add that config to main to make it easier to tackle these type issues.

I am 100% in agreeance we need to fix these type issues and the longer we wait the worse it is going to get. I am very happy to help out in fixing these too, and I don't think it will take that long.

I started small with math_utils.py here #1544

If you don't mind I'll assign myself to this issue in addition so I can help out with this task