Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add runtime and static type checks #639

Merged
merged 14 commits into from
Jan 10, 2025
Merged

Add runtime and static type checks #639

merged 14 commits into from
Jan 10, 2025

Conversation

Flova
Copy link
Member

@Flova Flova commented Dec 20, 2024

Summary

Many of our typehints are wrong. This adds beartype based type checks during runtime and static mypy checks to prevent this.

Proposed changes

  • Add beartype
  • Fix errors
  • Fit unrelated crash in animation ui that made testing hard.
  • Add mypy base tests

This adds some risk, as it might lead to a less frequently visited code part with a minor type error crashing our codebase during a game. We could downgrade the errors to warnings, but then they might not be noticed/ignored. We could also deactivate them during real games, but we do not have a mechanic to check for this yet.

We need to test this on the real robot before merging it!

Checklist

  • Run colcon build
  • Write documentation
  • Test on your machine
  • Test on the robot
  • Create issues for future work
  • Triage this PR and label it

@Flova Flova changed the title Add runtime type checks Add runtime and static type checks Dec 21, 2024
@Flova
Copy link
Member Author

Flova commented Jan 5, 2025

Ping :)

Copy link
Member

@jaagut jaagut left a comment

Choose a reason for hiding this comment

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

Uff

@@ -221,9 +221,11 @@
"ros.distro": "iron",
"search.useIgnoreFiles": false,
"python.autoComplete.extraPaths": [
"/opt/openrobots/lib/python3.10/site-packages",
Copy link
Member

Choose a reason for hiding this comment

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

Should this be here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really, but VS code always adds it and I dont want to make a special rule.

@@ -9,6 +10,7 @@
class AbstractBlackboardCapsule:
"""Abstract class for blackboard capsules."""

def __init__(self, node: Node, blackboard: Optional["BodyBlackboard"] = None):
@nobeartype
Copy link
Member

Choose a reason for hiding this comment

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

why is nobeartype needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

This has something to do with circular imports. The blackboard is imported for static type checking, but importing it for dynamic type checking leads to a circular dependency during runtime. Afaik bear type has no mechanism to handle this.

Comment on lines +40 to +41
<test_depend>ament_mypy</test_depend>
<test_depend>ament_cmake_mypy</test_depend>
Copy link
Member

Choose a reason for hiding this comment

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

why did you depend on both? In other cases, you only use one of them

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe because this is a cmake python package and the other ones are setup.py. I don't remember.

@Flova Flova merged commit c88ae76 into main Jan 10, 2025
2 checks passed
@Flova Flova deleted the feature/runtime_type_checks branch January 10, 2025 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants