Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve typing for BS4 element.Tag's get and get_attribute_list. #12840

Merged
merged 4 commits into from
Oct 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading