Skip to content

Conversation

@elkal98
Copy link

@elkal98 elkal98 commented Oct 19, 2025

Hi, I'm getting the below error:

src/scriptworker_client/github_client.py:176: error: Incompatible types in assignment (expression has type "None", target has type "Union[str, dict[str, Optional[str]]]") [assignment]

I think its happening when I set ret[name] = None. I tried to change the return type to include None, but that ended up creating errors in other places that use this function indirectly. So, can you please let me know how to resolve this or if I need to do any other changes.

Copy link
Contributor

@bhearsum bhearsum left a comment

Choose a reason for hiding this comment

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

This is a fine start. Please take a closer read of https://bugzilla.mozilla.org/show_bug.cgi?id=1968280#c0 to make sure you're making all of those changes, most of which I've highlighted in the comments here.

src/scriptworker_client/github_client.py:176: error: Incompatible types in assignment (expression has type "None", target has type "Union[str, dict[str, Optional[str]]]") [assignment]

This will probably be fixed as a side effect of my requested changes to the get_files signature.

orig_contents = ""
fromfile = "/dev/null"
add_remove_metadata = "new file mode 100644\n"
add_remove_metadata = f"new file mode {mode or 100644}\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than having a default here, this function should raise an error if mode is not set when a file is being newly added or removed.


async def get_files(self, files: Union[str, List[str]], branch: Optional[str] = None, files_per_request: int = 200) -> Dict[str, Union[str, None]]:
async def get_files(
self, files: Union[str, List[str]], branch: Optional[str] = None, files_per_request: int = 200, mode: Optional[str] = None
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not quite right - we want a boolean argument called something like fetch_mode that defaults to False. When True it should:

  • Change the query to fetch file modes
  • Return file modes in the return value

if mode:
ret[name] = {"mode": v.get("mode"), "text": v.get("text")}
else:
ret[name] = v.get("text")
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's update the value for each file to always be a dict; that will make things easier for callers, and make the function more comprehensible (especially the type signatures).

toml_files = [info.toml_path for info in android_l10n_import_info.toml_info]
# we always take the tip of the default branch when importing new strings
toml_contents = await l10n_github_client.get_files(toml_files)
toml_contents = await l10n_github_client.get_files(toml_files, mode=None)
Copy link
Contributor

Choose a reason for hiding this comment

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

After you've updated get_files as noted below, the l10n_github_client.get_files calls in this function and android_l10n_sync.py will need to be updated to set fetch_mode=True.

You will also need changes to actually pass the modes along to diff_contents for each file.

try:
log.info(f"fetching bump files from github: {files}")
orig_files = await github_client.get_files(files, branch)
orig_files = await github_client.get_files(files, branch, mode=None)
Copy link
Contributor

Choose a reason for hiding this comment

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

This specific change should not be needed (see my comment elsewhere about the interface of get_files. You will need to changes to this and all other get_files calls to deal with the fact that it will now be returning dicts for each file, rather than strings.

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.

2 participants