Skip to content

Commit

Permalink
Support builtin str removeprefix/removesuffix
Browse files Browse the repository at this point in the history
  • Loading branch information
jdimatteo committed Oct 18, 2021
1 parent aee09b6 commit 73ea72b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pytype/stubs/builtins/builtins.pytd
Expand Up @@ -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: ...
Expand Down
12 changes: 12 additions & 0 deletions pytype/tests/test_builtins4.py
Expand Up @@ -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
Expand Down

0 comments on commit 73ea72b

Please sign in to comment.