Skip to content

[lint][devex] Lint mypy#1

Merged
asaiacai merged 2 commits into
mainfrom
lint-mypy
Dec 16, 2025
Merged

[lint][devex] Lint mypy#1
asaiacai merged 2 commits into
mainfrom
lint-mypy

Conversation

@asaiacai

Copy link
Copy Markdown

adds linting and types

@asaiacai asaiacai merged commit ddc7c0e into main Dec 16, 2025
3 checks passed
@asaiacai asaiacai deleted the lint-mypy branch December 16, 2025 10:09
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @asaiacai, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly elevates the project's code quality and maintainability by integrating mypy for static type checking and enforcing consistent linting standards. The changes involve adding extensive type annotations throughout the codebase and standardizing string literal usage, which collectively contribute to a more robust and easier-to-understand system.

Highlights

  • Type Hinting Integration: Introduced comprehensive type annotations across numerous Python modules to enhance code clarity, reduce potential runtime errors, and improve maintainability. This includes adding Optional, List, Dict, Any, Callable, Union, Tuple, Iterable, Mapping, and cast from the typing module.
  • Mypy Linting Setup: Configured mypy for static type checking by adding it to development dependencies in pyproject.toml and setting ignore_missing_imports = true to manage external library type stubs.
  • Code Style and Formatting: Applied consistent linting rules, primarily converting string literals from double quotes to single quotes across the codebase, along with minor formatting adjustments like newline management and f-string usage.
  • Robustness Improvements: Enhanced error handling and data validation in mlop/file.py for file paths and in mlop/sys.py for collecting Python package requirements, ensuring more stable operations.
  • API Communication Logging: Improved logging for API retry attempts in mlop/iface.py to provide more detailed feedback on network communication issues.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request primarily focuses on refactoring the codebase for improved type hinting, consistency in string literal usage (changing double quotes to single quotes), and minor code cleanup across various modules. Key changes include updating README badges and URLs to reflect new branding, adding comprehensive type annotations to variables and function signatures in __init__.py, file.py, iface.py, init.py, op.py, sets.py, store.py, and sys.py. Error messages and warnings have been refined for better readability, and some critical logging statements were replaced with ValueError exceptions for more robust error handling, particularly in video data processing. Additionally, the pyproject.toml file was updated to include ignore_missing_imports = true for MyPy configuration. Review comments highlighted the need to address mutable default arguments in make_compat_graph_nodes_v1, get_shape, and Graph.__init__ to prevent unexpected behavior and state leakage, and to ensure self._dataframe is properly handled in Table.to_data to avoid AttributeError.

Comment thread mlop/api.py
name = "."
elif p == ".":
name = str(d["name"])
def make_compat_graph_nodes_v1(d, ref, dep=0, p='', r={}):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Using a mutable default argument like r={} can lead to unexpected behavior, as the dictionary will be shared across all calls to this function that don't explicitly provide r. This can cause state to leak between different graph constructions. It's safer to initialize r to None and create a new dictionary inside the function if r is None.

After changing the signature, please add if r is None: r = {} as the first line of the function.

Suggested change
def make_compat_graph_nodes_v1(d, ref, dep=0, p='', r={}):
def make_compat_graph_nodes_v1(d, ref, dep=0, p='', r=None):

Comment thread mlop/compat/torch.py
return info


def get_shape(tensor, r=set()):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Using a mutable default argument r=set() is dangerous because the set will be shared across different calls to get_shape. This means that visited nodes from one call will persist and affect subsequent calls, potentially leading to incorrect shape calculations if the function is used on different tensors. To avoid this, you should default to None and create a new set within the function.

After changing the signature, please add if r is None: r = set() as the first line of the function.

Suggested change
def get_shape(tensor, r=set()):
def get_shape(tensor, r=None):

Comment thread mlop/data.py
self._pd = self._dataframe.to_dict(orient="split")
self._table = self._pd.get("data", [[None]])
if data.__class__.__name__ == 'DataFrame' and hasattr(data, 'to_dict'):
self._pd = self._dataframe.to_dict(orient='split')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

There's a potential AttributeError here. The code uses self._dataframe.to_dict(), but self._dataframe could be None if a DataFrame is passed via the data positional argument instead of the dataframe keyword argument. You should use the data variable which holds the correct object in both cases.

Suggested change
self._pd = self._dataframe.to_dict(orient='split')
self._pd = data.to_dict(orient='split')

Comment thread mlop/data.py
tag = "Graph"
tag = 'Graph'

def __init__(self, data={}):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using a mutable default argument like data={} is generally discouraged. While it might seem to work here because you're only reading from it with .get(), it can lead to subtle bugs if the code is changed later. It's safer to use data=None and initialize it to an empty dictionary inside the function.

After changing the signature, please add if data is None: data = {} as the first line of the function.

Suggested change
def __init__(self, data={}):
def __init__(self, data=None):

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.

1 participant