Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

434: Static Type Checker Mypy added to CI & as a poe task in pyproject.toml #507

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

adigidh
Copy link
Contributor

@adigidh adigidh commented Mar 6, 2025

Which issue(s) does this pull-request address?

Closes: #434

Description

Added MyPy type checking as a poe task and as a CI workflow action. Added in tasks for different type checking scenarios.

type-check = "mypy ."
type-check-strict = "mypy --strict ."
type-check-verbose = "mypy --verbose --show-error-context --pretty ."

Captured examples of failures in the Git Actions: https://github.com/i-am-bee/beeai-framework/actions/runs/13707535290/job/38336396042?pr=507

Example failures while running these locally: poetry run poe type-check-strict
image

Checklist

  • I have read the contributor guide
  • I have signed off on my commit
  • Linting passes: yarn lint or yarn lint:fix
  • Formatting is applied: yarn format or yarn format:fix
  • Unit tests pass: yarn test:unit
  • E2E tests pass: yarn test:e2e
  • Tests are included
  • Documentation is changed or added
  • Commit messages and PR title follow conventional commits

@adigidh adigidh requested review from a team as code owners March 6, 2025 16:02
@adigidh adigidh force-pushed the mypy-poe-typecheck branch 2 times, most recently from eea2e47 to 33568c5 Compare March 6, 2025 16:13
@ajbozarth
Copy link
Member

This looks great, would you be willing to look into addressing the top level mypy failures while you're at it. We should be able to config mypy in pyproject.toml to allow duplicate module names in separate subdirectories.

adigidh added 4 commits March 6, 2025 15:23
Signed-off-by: Aditya Gidh <aagidh@us.ibm.com>
Signed-off-by: Aditya Gidh <aagidh@us.ibm.com>
Signed-off-by: Aditya Gidh <aagidh@us.ibm.com>
Signed-off-by: Aditya Gidh <aagidh@us.ibm.com>
@adigidh adigidh force-pushed the mypy-poe-typecheck branch from 9fb92b8 to e14069a Compare March 6, 2025 20:26
Signed-off-by: Aditya Gidh <aagidh@us.ibm.com>
@adigidh adigidh force-pushed the mypy-poe-typecheck branch from e14069a to 830ca5a Compare March 6, 2025 20:27
@adigidh
Copy link
Contributor Author

adigidh commented Mar 6, 2025

This looks great, would you be willing to look into addressing the top level mypy failures while you're at it. We should be able to config mypy in pyproject.toml to allow duplicate module names in separate subdirectories.

@ajbozarth : Initially I updated mypy’s configuration to allow for duplicate module names in separate subdirectories.

namespace_packages = true: Allows mypy to recognize namespaces without requiring __init__.py files in every directory.

explicit_package_bases = true: Ensures mypy uses the directory structure (relative to the root).

But it complained about other things with "Source file found twice under different module names". Therefore added empty __init__.py files to enforce a namespace, offering a cleanest way to fix both issues spotted earlier. Let me know what you think!

@ajbozarth
Copy link
Member

But it complained about other things with "Source file found twice under different module names". Therefore added empty init.py files to enforce a namespace, offering a cleanest way to fix both issues spotted earlier. Let me know what you think!

Thanks, I checked it out and played with it a bit and I think you only need the init.py at the root of examples to fix it, so you can delete the others. Otherwise I think this is g2g

@@ -245,6 +245,12 @@ help = "Extract Python files only"
args = [{ name = "TARGET", positional = true, multiple = true }]
shell = "printf '%s\\n' $TARGET | grep -E '\\.(py|ipynb)$' | tr '\\n' ' '"

[tool.poe.tasks]
Copy link
Member

@ajbozarth ajbozarth Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should work like poe lint and poe format, so this would be [tool.poe.tasks.type-check] and reformat the following lines to work similar to the other poe.tasks section above

@ajbozarth ajbozarth added the python Python related functionality label Mar 6, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
python Python related functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add mypy to CI
2 participants