Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 28, 2025

Summary

This PR removes all Python 2 backward compatibility code from the Beaker codebase, making it Python 3.8+ only. This resolves the issue where pyupgrade --py38-plus would break the code.

Changes Made

Core Compatibility Module (beaker/_compat.py)

  • Completely rewritten to remove all Python 2 code
  • Removed: PY2, JYTHON, PYVER, xrange_, add_metaclass, exec_, reraise
  • Per reviewer feedback: Removed type aliases (NoneType, string_type, unicode_text, byte_string) - use native types directly
  • Per reviewer feedback: Removed u_() function - use str directly

Files Updated to Use Native Types

  • beaker/util.py: Use str, type(None) instead of aliases
  • beaker/cache.py: Use str instead of unicode_text, str() instead of u_()
  • beaker/session.py: Use str instead of string_type
  • beaker/container.py: Removed unused unicode_text import
  • beaker/converters.py: Use str instead of string_type
  • beaker/ext/{mongodb,redisnm,redisclusternm}.py: Use str instead of string_type
  • Test files: Replaced u_('...') with '...'

Other Changes

  • setup.py: Added python_requires='>=3.8'
  • cookie.py: Removed old Python version workarounds
  • crypto/pbkdf2.py: Removed fallback PBKDF2 implementation
  • container.py: Native metaclass= syntax

Test Results

  • All core tests pass
  • Fixed remaining u_() usages in tests/test_managers/base.py and tests/test_unicode_cache_keys.py that were causing CI failures
Original prompt

This section details on the original issue you should resolve

<issue_title>1.13.0: not ready for pyupgrade --py38-plus</issue_title>
<issue_description>Python 3.7 has been EOSed 27 Jun 2023 so I've been trying to update beaker code to python 3.8 using pyupgrade --py38-plus.
After apply patch generated by tis filter I found that pytest is failing

Here is pytest output:
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-beaker-1.13.0-2.fc37.x86_64/usr/lib64/python3.10/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-beaker-1.13.0-2.fc37.x86_64/usr/lib/python3.10/site-packages
+ /usr/bin/pytest -ra -m 'not network' --deselect tests/test_cache.py --deselect tests/test_cache_decorator.py --deselect tests/test_cachemanager.py --deselect tests/test_container.py --deselect tests/test_cookie_domain_only.py --deselect tests/test_cookie_expires.py --deselect tests/test_cookie_only.py --deselect tests/test_database.py --deselect tests/test_domain_setting.py --deselect tests/test_increment.py --deselect tests/test_managers/test_ext_mongodb.py --deselect tests/test_managers/test_ext_redis.py --deselect tests/test_managers/test_ext_rediscluster.py --deselect tests/test_memcached.py --deselect tests/test_session.py --deselect tests/test_sqla.py --deselect tests/test_unicode_cache_keys.py
3657536:C 23 Sep 2024 20:17:37.619 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
3657536:C 23 Sep 2024 20:17:37.619 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
3657536:C 23 Sep 2024 20:17:37.619 * Redis version=7.4.0, bits=64, commit=00000000, modified=0, pid=3657536, just started
3657536:C 23 Sep 2024 20:17:37.619 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
3657536:M 23 Sep 2024 20:17:37.620 * Increased maximum number of open files to 10032 (it was originally set to 1024).
3657536:M 23 Sep 2024 20:17:37.620 * monotonic clock: POSIX clock_gettime
3657536:M 23 Sep 2024 20:17:37.622 * Running mode=standalone, port=6379.
3657536:M 23 Sep 2024 20:17:37.622 # Warning: Could not create server TCP listening socket *:6379: bind: Address already in use
3657536:M 23 Sep 2024 20:17:37.622 # Failed listening on port 6379 (tcp), aborting.
============================= test session starts ==============================
platform linux -- Python 3.10.14, pytest-8.2.2, pluggy-1.5.0
rootdir: /home/tkloczko/rpmbuild/BUILD/beaker-1.13.0
configfile: setup.cfg
collected 19 items / 17 errors

==================================== ERRORS ====================================
_____________________ ERROR collecting tests/test_cache.py _____________________
/usr/lib/python3.10/site-packages/_pytest/python.py:492: in importtestmodule
    mod = import_path(
/usr/lib/python3.10/site-packages/_pytest/pathlib.py:591: in import_path
    importlib.import_module(module_name)
/usr/lib64/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1050: in _gcd_import
    ???
<frozen importlib._bootstrap>:1027: in _find_and_load
    ???
<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:688: in _load_unlocked
    ???
/usr/lib/python3.10/site-packages/_pytest/assertion/rewrite.py:178: in exec_module
    exec(co, module.__dict__)
tests/test_cache.py:9: in <module>
    from beaker.middleware import CacheMiddleware
beaker/middleware.py:11: in <module>
    from beaker.cache import CacheManager
beaker/cache.py:20: in <module>
    import beaker.ext.database as database
beaker/ext/database.py:11: in <module>
    from beaker.ext.sqla import SqlaNamespaceManager
E     File "/home/tkloczko/rpmbuild/BUILD/beaker-1.13.0/beaker/ext/sqla.py", line 84
E       log.debug OSError
E                 ^^^^^^^
E   SyntaxError: invalid syntax
________________ ERROR collecting tests/test_cache_decorator.py ________________
/usr/lib/python3.10/site-packages/_pytest/python.py:492: in importtestmodule
    mod = import_path(
/usr/lib/python3.10/site-packages/_pytest/pathlib.py:591: in import_path
    importlib.import_module(module_name)
/usr/lib64/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1050: in _gcd_import
    ???
<frozen importlib._bootstrap>:1027: in _find_and_load
    ???
<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:68...

</details>

- Fixes bbangert/beaker#244

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.

Co-authored-by: amol- <601423+amol-@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix pytest failures after updating beaker to Python 3.8 Remove Python 2 compatibility code for Python 3.8+ Nov 28, 2025
Copilot AI requested a review from amol- November 28, 2025 22:26
@amol- amol- marked this pull request as ready for review November 28, 2025 22:26
Co-authored-by: amol- <601423+amol-@users.noreply.github.com>
Co-authored-by: amol- <601423+amol-@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants