Skip to content

Bytes formatting error gets produced during failed overload match #12665

Closed
@JelleZijlstra

Description

@JelleZijlstra

Bug Report

On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc" gets produced during bidirectional inference in a failed overload match.

To Reproduce

from typing import overload, Callable

@overload
def sub(pattern: str, repl: Callable[[str], str]) -> str: ...
@overload
def sub(pattern: bytes, repl: Callable[[bytes], bytes]) -> bytes: ...
def sub(pattern: object, repl: object) -> object:
    raise NotImplementedError

def better_snakecase(text: str) -> str:
    text = sub(r"([A-Z])([A-Z]+)([A-Z](?:[^A-Z]|$))", lambda match: f"{match}")
    return text

Expected Behavior

No errors

Actual Behavior

test_cases/stdlib/typing/pattern.py:11: error: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior

Your Environment

  • Mypy version used: master, 0.942
  • Mypy command-line flags: none

Found in python/typeshed#7679, the repro case minified from some code in homeassistant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions