Skip to content

Conversation

skools-here
Copy link
Contributor

Description
This PR introduces type annotations to the augur\application\db\util.py file and adds mypy for static type checking.
This PR fixes #3274

Changes included:

  1. Ran mypy locally on the project and fixed all type issues in this file and made mypy.ini so we can add more files in future for types checking.
  2. Starting with smaller utility/helper files as suggested, focusing on the ORM/database access layer.

Notes for Reviewers

Signed commits

  • Yes, I signed my commits.

@skools-here skools-here force-pushed the fix-db-types branch 2 times, most recently from 8b20725 to c7734aa Compare September 20, 2025 13:51
Copy link
Contributor

@MoralCode MoralCode left a comment

Choose a reason for hiding this comment

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

seems like an okay first pass (i still need to test it locally)

Overall notes:

  • any changes to the actual logic are likely going to slow this down a fair bit as the logic needs testing to make sure it behaves the same
  • also, try to avoid using Any as a type if you can at all avoid it - its not very helpful at enforcing typings since it accepts anything.

Comment on lines 13 to 17

# do the sleep here instead of instead of in the exception
# so it doesn't sleep after the last failed time
if attempts > 0:
#Do a 30% exponential backoff
# Do a 30% exponential backoff
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems like a non-typing change that removed a helpful comment - was this removed on purpose?


def convert_orm_list_to_dict_list(result):
new_list = []
def convert_orm_list_to_dict_list(result: List[Any]) -> List[Dict[str, Any]]:
Copy link
Contributor

Choose a reason for hiding this comment

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

it might be nice to not use Any as the type here - does the ORM have a base/parent class that all the ORM classes inherit from? maybe thats a better thing to use?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’ll update convert_orm_list_to_dict_list to use the ORM base class, and refine config_dict + logger to use more specific types (Optional[logging.Logger], etc.) .


data_type = config_dict["type"]
def convert_type_of_value(
config_dict: Dict[str, Any], logger: Optional[Any] = None
Copy link
Contributor

Choose a reason for hiding this comment

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

does config_dict come from somewhere? could its type be specified more precisely than Any? same with the logger

Comment on lines 67 to 79
if data_type == "str" or data_type is None:
if data_type is None or data_type == "str":
Copy link
Contributor

Choose a reason for hiding this comment

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

why was the order of these changed? this could cause a crash if the data type is none because it is relying on the short curcuiting behavior of or

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes i will fix this this .

else:
config_dict["value"] = True
value = str(config_dict["value"]).lower()
config_dict["value"] = value != "false"
Copy link
Contributor

Choose a reason for hiding this comment

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

if value is exactly false (string), this will evaluate to true.

Copy link
Contributor

Choose a reason for hiding this comment

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

wait did i get this wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the earlier function (Not type safe one) already had that anything not false is True behavior. So according to me this must work i am not sure though .

@skools-here
Copy link
Contributor Author

Yes thanks for the review will be changing all the logic changes which may cause problem and will also try to reduce the use of any .

@MoralCode
Copy link
Contributor

we should also probably add a CI job to check the types so its clear if something breaks on a pull request

"pytest==6.2.5",
"toml>=0.10.2",
"ipdb==0.13.9",
"mypy>=1.8.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

if you change this file, you also need to run uv sync and commit the changes to the uv.lock file. this will likely help some of the CI jobs pass

Signed-off-by: Sajal-Kulshreshtha <sajalkulshreshtha9@gmail.com>
Signed-off-by: Sajal-Kulshreshtha <sajalkulshreshtha9@gmail.com>
Signed-off-by: Sajal-Kulshreshtha <sajalkulshreshtha9@gmail.com>
Signed-off-by: Sajal-Kulshreshtha <sajalkulshreshtha9@gmail.com>
Signed-off-by: Sajal-Kulshreshtha <sajalkulshreshtha9@gmail.com>
Signed-off-by: Sajal-Kulshreshtha <sajalkulshreshtha9@gmail.com>
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.

Add CI job to check and enforce python typing information to ensure quality
2 participants