Skip to content

Commit 7043ec2

Browse files
author
Kevin Mustelier
authored
Improve typing for BS4 element.Tag's get and get_attribute_list. (#12840)
1 parent b2f68ec commit 7043ec2

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

stubs/beautifulsoup4/bs4/element.pyi

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ContentMetaAttributeValue(AttributeValueWithCharsetSubstitution):
2727
def __new__(cls, original_value): ...
2828
def encode(self, encoding: str) -> str: ... # type: ignore[override] # incompatible with str
2929

30+
_T = TypeVar("_T")
3031
_PageElementT = TypeVar("_PageElementT", bound=PageElement)
3132
_SimpleStrainable: TypeAlias = str | bool | None | bytes | Pattern[str] | Callable[[str], bool] | Callable[[Tag], bool]
3233
_Strainable: TypeAlias = _SimpleStrainable | Iterable[_SimpleStrainable]
@@ -276,8 +277,16 @@ class Tag(PageElement):
276277
def clear(self, decompose: bool = False) -> None: ...
277278
def smooth(self) -> None: ...
278279
def index(self, element: PageElement) -> int: ...
279-
def get(self, key: str, default: str | list[str] | None = None) -> str | list[str] | None: ...
280-
def get_attribute_list(self, key: str, default: str | list[str] | None = None) -> list[str]: ...
280+
@overload
281+
def get(self, key: str, default: None = None) -> str | list[str] | None: ...
282+
@overload
283+
def get(self, key: str, default: _T) -> str | list[str] | _T: ...
284+
@overload
285+
def get_attribute_list(self, key: str, default: None = None) -> list[str | None]: ...
286+
@overload
287+
def get_attribute_list(self, key: str, default: list[_T]) -> list[str | _T]: ...
288+
@overload
289+
def get_attribute_list(self, key: str, default: _T) -> list[str | _T]: ...
281290
def has_attr(self, key: str) -> bool: ...
282291
def __hash__(self) -> int: ...
283292
def __getitem__(self, key: str) -> str | list[str]: ...

0 commit comments

Comments
 (0)