_StrainableAttribute type does not allow None as argument
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Beautiful Soup |
New
|
Undecided
|
Unassigned |
Bug Description
This bug is about one of the type hints provided with BeautifulSoup4.
When filtering an attribute with a lambda function, BeautifulSoup will provide an input argument of None to the lambda if the attribute does not exist on elements. However, the current type hint for `_StrainableAtt
Python Version: 3.11.4
BeautifulSoup Version: 4.13.4 with "html.parser"
System: Windows 11
Reproduction:
import bs4
html = '<html>
soup = bs4.BeautifulSo
links = soup.find_all('a', href=lambda x: ".org" in x)
# This type checks (lambda is Callable[[str], bool]), but will throw at runtime
import bs4
html = '<html>
soup = bs4.BeautifulSo
links = soup.find_all('a', href=lambda x: x is not None and ".org" in x)
# This will work at runtime, but will fail type checks (lambda is Callable[