async attribute in python 3.7+
Bug #1878740 reported by
Alexei Martchenko
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Beautiful Soup |
Won't Fix
|
Undecided
|
Unassigned |
Bug Description
Async is a reserved word in Python 3.7. Thus, it cannot be used as argument.
This code works perfectly in Python 2.7 (and 3.2 to 3.6 I believe) but not in 3.7.6
>>> from bs4 import BeautifulSoup
>>> soup = BeautifulSoup(
>>> new_tag = soup.new_
File "<stdin>", line 1
new_tag = soup.new_
SyntaxError: invalid syntax
Should BS4 use _async like _class?
To post a comment you must log in.
Thanks for taking the time to file this issue.
'class' gets special treatment in find() and similar methods because CSS class is the single most common way people look for a tag. It doesn't get special treatment in new_tag(), and 'async' is much less common, so my recommendation is to use the 'attrs' argument instead of Python keyword arguments:
new_tag = soup.new_ tag('script' , attrs={'async': None}, src="https:/ /platform. twitter. com/widgets. js", charset="utf-8")
In revision 574 I improved the new_tag() docstring to mention this possibility.