Skip to content

Strange Index error on string formatting #9221

Description

@staticdev
  • Are you reporting a bug, or opening a feature request? Bug.
  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.
import github # PyGithub
g = github.Github("access_token")
github_repo = "staticdev/git-portfolio"
repo = g.get_repo(github_repo)
try:
    created_pr = repo.create_pull(
        title="title", body="body", head="head", base="base", draft=False,
    )
except github.GithubException as github_exception:
    extra = ""
    for error in github_exception.data["errors"]:
        if "message" in error:
            extra += f"{error['message']} "
        else:
            extra += f"Invalid field {error['field']}. "
  • What is the actual behavior/output?
src/git_portfolio/mypy.py:13:31: error: Invalid index type "str" for "Union[str, Dict[str, str]]"; expected type "Union[int, slice]"  [index]
                extra += f"{error['message']} "
                                  ^
src/git_portfolio/mypy.py:15:45: error: Invalid index type "str" for "Union[str, Dict[str, str]]"; expected type "Union[int, slice]"  [index]
                extra += f"Invalid field {error['field']}. "
                                                ^
  • What is the behavior/output you expect?
    I expected no error, since I did not declare any type for f-strings, and these are strings.

  • What are the versions of mypy and Python you are using?
    mypy v0.782 python 3.8.2

    Do you see the same issue after installing mypy from Git master?
    yes

  • What are the mypy flags you are using? (For example --strict-optional)
    None.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions