Skip to content

Commit

Permalink
Improve typing for BS4 element.Tag's get and get_attribute_list. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kemus authored Oct 19, 2024
1 parent b2f68ec commit 7043ec2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions stubs/beautifulsoup4/bs4/element.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ContentMetaAttributeValue(AttributeValueWithCharsetSubstitution):
def __new__(cls, original_value): ...
def encode(self, encoding: str) -> str: ... # type: ignore[override] # incompatible with str

_T = TypeVar("_T")
_PageElementT = TypeVar("_PageElementT", bound=PageElement)
_SimpleStrainable: TypeAlias = str | bool | None | bytes | Pattern[str] | Callable[[str], bool] | Callable[[Tag], bool]
_Strainable: TypeAlias = _SimpleStrainable | Iterable[_SimpleStrainable]
Expand Down Expand Up @@ -276,8 +277,16 @@ class Tag(PageElement):
def clear(self, decompose: bool = False) -> None: ...
def smooth(self) -> None: ...
def index(self, element: PageElement) -> int: ...
def get(self, key: str, default: str | list[str] | None = None) -> str | list[str] | None: ...
def get_attribute_list(self, key: str, default: str | list[str] | None = None) -> list[str]: ...
@overload
def get(self, key: str, default: None = None) -> str | list[str] | None: ...
@overload
def get(self, key: str, default: _T) -> str | list[str] | _T: ...
@overload
def get_attribute_list(self, key: str, default: None = None) -> list[str | None]: ...
@overload
def get_attribute_list(self, key: str, default: list[_T]) -> list[str | _T]: ...
@overload
def get_attribute_list(self, key: str, default: _T) -> list[str | _T]: ...
def has_attr(self, key: str) -> bool: ...
def __hash__(self) -> int: ...
def __getitem__(self, key: str) -> str | list[str]: ...
Expand Down

0 comments on commit 7043ec2

Please sign in to comment.