Skip to content

Commit 5f49273

Browse files
sobolevnautofix-ci[bot]
authored andcommitted
Remove incorrect usage of typing.AnyStr (mitmproxy#6271)
* Remove incorrect usage of `typing.AnyStr` Hi! While working on python/mypy#15732 our tools detected a misuse of AnyStr TypeVar (which is quite common). The proper way here is to use `@overload`s :) * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 37b118a commit 5f49273

File tree

1 file changed

+13
-2
lines changed
  • mitmproxy/tools/console/grideditor

1 file changed

+13
-2
lines changed

mitmproxy/tools/console/grideditor/base.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
from collections.abc import MutableSequence
88
from collections.abc import Sequence
99
from typing import Any
10-
from typing import AnyStr
1110
from typing import ClassVar
11+
from typing import Literal
12+
from typing import overload
1213

1314
import urwid
1415

@@ -19,7 +20,17 @@
1920
from mitmproxy.utils import strutils
2021

2122

22-
def read_file(filename: str, escaped: bool) -> AnyStr:
23+
@overload
24+
def read_file(filename: str, escaped: Literal[True]) -> bytes:
25+
...
26+
27+
28+
@overload
29+
def read_file(filename: str, escaped: Literal[False]) -> str:
30+
...
31+
32+
33+
def read_file(filename: str, escaped: bool) -> bytes | str:
2334
filename = os.path.expanduser(filename)
2435
try:
2536
with open(filename, "r" if escaped else "rb") as f:

0 commit comments

Comments
 (0)