Comment 5 for bug 1843791

Revision history for this message
Florian Schulze (florian-schulze) wrote :

``from __future__ import annotations`` fixes it (https://peps.python.org/pep-0563/), but then using ``|`` for types isn't supported before Python 3.10 https://peps.python.org/pep-0604/

```diff
diff --git a/bs4/__init__.py b/bs4/__init__.py
index 46c770f..b2c889a 100644
--- a/bs4/__init__.py
+++ b/bs4/__init__.py
@@ -13,6 +13,7 @@ and/or html5lib is installed, but they are not required.
 For more than you ever wanted to know about Beautiful Soup, see the
 documentation: http://www.crummy.com/software/BeautifulSoup/bs4/doc/
 """
+from __future__ import annotations

 __author__ = "Leonard Richardson (<email address hidden>)"
 __version__ = "4.12.2"
@@ -23,6 +24,7 @@ __license__ = "MIT"
 __all__ = ['BeautifulSoup']

 from collections import Counter
+from typing import Union
 import os
 import re
 import sys
@@ -376,7 +378,7 @@ class BeautifulSoup(Tag):

         # At this point we know markup is a string or bytestring. If
         # it was a file-type object, we've read from it.
- markup = cast(str|bytes, markup)
+ markup = cast(Union[str, bytes], markup)

         rejections = []
         success = False
```