diff --git a/pytype/stubs/builtins/builtins.pytd b/pytype/stubs/builtins/builtins.pytd index 10ef53cd5..ccc71564a 100644 --- a/pytype/stubs/builtins/builtins.pytd +++ b/pytype/stubs/builtins/builtins.pytd @@ -304,6 +304,8 @@ class str(Sequence[str], Hashable): def lower(self) -> str: ... def lstrip(self, chars: Optional[str] = ...) -> str: ... def partition(self, sep: str) -> Tuple[str, str, str]: ... + def removeprefix(self, prefix: str) -> str: ... + def removesuffix(self, suffix: str) -> str: ... def replace(self, old: str, new: str, *args, **kwargs) -> str: ... def rfind(self, sub: str, *args, **kwargs) -> int: ... def rindex(self, sub: str, *args, **kwargs) -> int: ... diff --git a/pytype/tests/test_builtins4.py b/pytype/tests/test_builtins4.py index c55252e3c..9223137ac 100644 --- a/pytype/tests/test_builtins4.py +++ b/pytype/tests/test_builtins4.py @@ -286,6 +286,18 @@ def test_str_join(self): h = ... # type: str """) + def test_str_remove_prefix_suffix(self): + ty = self.Infer(""" + a = "prefix_suffix" + b = a.removeprefix("prefix_") + c = a.removesuffix("_suffix") + """, deep=False) + self.assertTypesMatchPytd(ty, """ + a = ... # type: str + b = ... # type: str + c = ... # type: str + """) + def test_str_is_hashable(self): self.Check(""" from typing import Any, Dict, Hashable