{"id":7422,"library":"mo-future","title":"mo-future","description":"mo-future is a Python library designed to simplify Python 2/3 compatibility, aiming to be easier to use than `future` or `six`. It provides a flat namespace for common compatibility types and functions. The current version is 7.685.25166, with releases indicating active development.","status":"active","version":"7.685.25166","language":"en","source_language":"en","source_url":"https://github.com/klahnakoski/mo-future","tags":["Python 2/3 compatibility","utility","backport","forward-port"],"install":[{"cmd":"pip install mo-future","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"mo-future provides a flat namespace, eliminating the need to search for symbols in submodules of compatibility libraries like `future` or `six`.","wrong":"from future.utils import text","symbol":"text","correct":"from mo_future import text"},{"note":"For Python 2/3 compatible byte string types, mo-future exposes `bytes` directly.","wrong":"from six import binary_type","symbol":"bytes","correct":"from mo_future import bytes"}],"quickstart":{"code":"from mo_future import text, bytes, range, map\n\n# Example of using Python 3-like builtins compatible with Python 2 (if applicable)\nprint(type(text('hello')))\nprint(type(bytes(b'world')))\n\n# range and map behave like their Python 3 counterparts (returning iterators)\nmy_range = range(5)\nprint(list(my_range))\n\nmy_map = map(lambda x: x * 2, [1, 2, 3])\nprint(list(my_map))\n\n# A simple compatibility check (example, not actual mo_future feature)\ntry:\n    from urllib.request import urlopen\nexcept ImportError:\n    from urllib2 import urlopen\n    print('Using urllib2 (Python 2 pattern)')\nelse:\n    print('Using urllib.request (Python 3 pattern)')","lang":"python","description":"This quickstart demonstrates how to import and use some common compatibility shims provided by mo-future. It aims to offer Python 3-like behavior for types and functions, abstracting away Python 2/3 differences with simpler top-level imports."},"warnings":[{"fix":"Review your codebase for any Python 2-specific logic using `mo-future` shims. For truly Python 2-only compatibility, consider pinning to an older version or migrating away from Python 2 entirely.","message":"As of December 2022, mo-future no longer points to Python 2-specific modules. This means code relying on `mo-future` for direct Python 2 compatibility features might break.","severity":"breaking","affected_versions":">= 7.x (since December 2022)"},{"fix":"Always import directly from the top-level `mo_future` module. For example, use `from mo_future import text` instead of `from future.utils import text` or `from six import text_type`.","message":"Users migrating from `python-future` or `six` might incorrectly assume `mo-future` maintains the same submodule structure (e.g., `future.utils`). `mo-future` promotes a flat namespace.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Refer to the project's GitHub repository for detailed change logs and release notes to understand specific version differences.","message":"The versioning scheme (e.g., 7.685.25166) appears highly granular or potentially generated. While this indicates active development, it might make tracking specific feature introductions or deprecations difficult without detailed release notes.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Change the import statement to `from mo_future import text`. mo-future provides a flat namespace.","cause":"Attempting to import compatibility symbols from `future.utils` when `mo-future` expects a direct import from its top-level module.","error":"ImportError: cannot import name 'text' from 'future.utils'"},{"fix":"If your project targets only Python 3, this attribute is no longer needed. If you require Python 2 compatibility, you may need to either use an older version of `mo-future` or implement Python 2-specific logic outside of `mo-future`.","cause":"Attempting to access a Python 2-specific compatibility shim that was removed from `mo-future` after December 2022.","error":"AttributeError: module 'mo_future' has no attribute 'foo_py2_only'"},{"fix":"Explicitly convert the `map` object to a list if you need to access elements by index or iterate over it multiple times: `list(my_map)`. The `map` from `mo_future` behaves like Python 3's `map` which returns an iterator.","cause":"Treating the `map` function imported from `mo_future` as if it returns a list (Python 2 behavior) instead of an iterator (Python 3 behavior).","error":"TypeError: 'map' object is not subscriptable"}]}