Skip to content

Commit

Permalink
Monkey patch collections module to support Python 3.10.
Browse files Browse the repository at this point in the history
  • Loading branch information
rtibbles committed May 1, 2022
1 parent 045f10b commit 7c8e2da
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions kolibri/utils/compat.py
Expand Up @@ -82,3 +82,21 @@ def parse_version(v):
parsed = _parse_version(v)

return VersionCompat(parsed)


def monkey_patch_collections():
"""
Monkey-patching for the collections module is required for Python 3.10
and above.
Prior to 3.10, the collections module still contained all the entities defined in
collections.abc from Python 3.3 onwards. Here we patch those back into main
collections module.
"""
if sys.version_info < (3, 10):
return
import collections
from collections import abc

for name in dir(abc):
if not hasattr(collections, name):
setattr(collections, name, getattr(abc, name))
3 changes: 3 additions & 0 deletions kolibri/utils/env.py
Expand Up @@ -18,6 +18,7 @@
ColoredFormatter = None

from .logger import LOG_COLORS
from kolibri.utils.compat import monkey_patch_collections


logging.basicConfig(format="%(levelname)s: %(message)s", level=logging.INFO)
Expand Down Expand Up @@ -124,6 +125,8 @@ def set_env():

check_python_versions()

monkey_patch_collections()

sys.path = [os.path.realpath(os.path.dirname(kolibri_dist.__file__))] + sys.path

# Add path for c extensions to sys.path
Expand Down

0 comments on commit 7c8e2da

Please sign in to comment.