mirror of
https://git.launchpad.net/beautifulsoup
synced 2025-10-06 00:12:49 +02:00
Fixed a couple of pyright errors as long as I was playing around with it.
This commit is contained in:
@@ -51,6 +51,7 @@ __all__ = [
|
||||
]
|
||||
|
||||
from collections import Counter
|
||||
import io
|
||||
import sys
|
||||
import warnings
|
||||
|
||||
@@ -349,7 +350,7 @@ class BeautifulSoup(Tag):
|
||||
original_builder = builder
|
||||
original_features = features
|
||||
|
||||
builder_class: Type[TreeBuilder]
|
||||
builder_class: Optional[Type[TreeBuilder]] = None
|
||||
if isinstance(builder, type):
|
||||
# A builder class was passed in; it needs to be instantiated.
|
||||
builder_class = builder
|
||||
@@ -372,6 +373,7 @@ class BeautifulSoup(Tag):
|
||||
# builder, or we have a builder_class that we can instantiate
|
||||
# with the remaining **kwargs.
|
||||
if builder is None:
|
||||
assert builder_class is not None
|
||||
builder = builder_class(**kwargs)
|
||||
if (
|
||||
not original_builder
|
||||
@@ -437,7 +439,7 @@ class BeautifulSoup(Tag):
|
||||
self.parse_only = parse_only
|
||||
|
||||
if hasattr(markup, "read"): # It's a file-type object.
|
||||
markup = markup.read()
|
||||
markup = cast(io.IOBase, markup).read()
|
||||
elif not isinstance(markup, (bytes, str)) and not hasattr(markup, "__len__"):
|
||||
raise TypeError(
|
||||
f"Incoming markup is of an invalid type: {markup!r}. Markup must be a string, a bytestring, or an open filehandle."
|
||||
@@ -1118,6 +1120,7 @@ class BeautifulSoup(Tag):
|
||||
# argument to this method (or a keyword argument with the old
|
||||
# name), we can handle it and put out a DeprecationWarning.
|
||||
warning: Optional[str] = None
|
||||
pretty_print: Optional[bool] = None
|
||||
if isinstance(indent_level, bool):
|
||||
if indent_level is True:
|
||||
indent_level = 0
|
||||
|
@@ -136,7 +136,7 @@ class TreeBuilderRegistry(object):
|
||||
if candidates is None:
|
||||
candidates = we_have_the_feature
|
||||
candidate_set = set(candidates)
|
||||
else:
|
||||
elif candidate_set is not None:
|
||||
# Eliminate any candidates that don't have this feature.
|
||||
candidate_set = candidate_set.intersection(set(we_have_the_feature))
|
||||
|
||||
@@ -508,7 +508,7 @@ class HTMLTreeBuilder(TreeBuilder):
|
||||
|
||||
#: Some HTML tags are defined as having no contents. Beautiful Soup
|
||||
#: treats these specially.
|
||||
DEFAULT_EMPTY_ELEMENT_TAGS: Set[str] = set(
|
||||
DEFAULT_EMPTY_ELEMENT_TAGS: Optional[Set[str]] = set(
|
||||
[
|
||||
# These are from HTML5.
|
||||
"area",
|
||||
|
@@ -75,7 +75,7 @@ class HTML5TreeBuilder(HTMLTreeBuilder):
|
||||
|
||||
NAME: str = "html5lib"
|
||||
|
||||
features: Sequence[str] = [NAME, PERMISSIVE, HTML_5, HTML]
|
||||
features: Iterable[str] = [NAME, PERMISSIVE, HTML_5, HTML]
|
||||
|
||||
#: html5lib can tell us which line number and position in the
|
||||
#: original file is the source of an element.
|
||||
|
@@ -1512,7 +1512,7 @@ class Doctype(PreformattedString):
|
||||
|
||||
@classmethod
|
||||
def _string_for_name_and_ids(
|
||||
self, name: str, pub_id: Optional[str], system_id: Optional[str]
|
||||
cls, name: str, pub_id: Optional[str], system_id: Optional[str]
|
||||
) -> str:
|
||||
"""Generate a string to be used as the basis of a Doctype object.
|
||||
|
||||
|
Reference in New Issue
Block a user