From 04696c5f29e2df9508ef23b79453268942979f36 Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Sat, 15 Feb 2025 20:42:39 +0100 Subject: [PATCH] Remove more traces of Python2 (GH-280) --- README.rst | 2 +- lupa/__init__.py | 2 -- lupa/_lupa.pyx | 2 -- lupa/tests/__init__.py | 2 -- lupa/tests/test.py | 47 ++++++++++++++++++------------------------ setup.py | 2 -- 6 files changed, 21 insertions(+), 36 deletions(-) diff --git a/README.rst b/README.rst index 335e8ac3..272590b7 100644 --- a/README.rst +++ b/README.rst @@ -935,7 +935,7 @@ setter function implementations for a ``LuaRuntime``: ... raise AttributeError( ... 'not allowed to write attribute "%s"' % attr_name) - >>> class X(object): + >>> class X: ... yes = 123 ... put = 'abc' ... noway = 2.1 diff --git a/lupa/__init__.py b/lupa/__init__.py index 7b05b6e8..4529f078 100644 --- a/lupa/__init__.py +++ b/lupa/__init__.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - from contextlib import contextmanager as _contextmanager # Find the implementation with the latest Lua version available. diff --git a/lupa/_lupa.pyx b/lupa/_lupa.pyx index 8f4f73f5..43011f85 100644 --- a/lupa/_lupa.pyx +++ b/lupa/_lupa.pyx @@ -4,8 +4,6 @@ A fast Python wrapper around Lua and LuaJIT2. """ -from __future__ import absolute_import - cimport cython from libc.string cimport strlen, strchr diff --git a/lupa/tests/__init__.py b/lupa/tests/__init__.py index 7ee26aba..23eb3a80 100644 --- a/lupa/tests/__init__.py +++ b/lupa/tests/__init__.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import unittest import doctest import os diff --git a/lupa/tests/test.py b/lupa/tests/test.py index 674229b7..411be6b7 100644 --- a/lupa/tests/test.py +++ b/lupa/tests/test.py @@ -27,7 +27,7 @@ def _next(o): return o.next() -class SetupLuaRuntimeMixin(object): +class SetupLuaRuntimeMixin: lua_runtime_kwargs = {} def setUp(self): @@ -262,10 +262,7 @@ def test_none(self): def test_pybuiltins(self): function = self.lua.eval('function() return python.builtins end') - try: - import __builtin__ as builtins - except ImportError: - import builtins + import builtins self.assertEqual(builtins, function()) def test_pybuiltins_disabled(self): @@ -290,7 +287,7 @@ def test_call_str_py(self): def test_call_str_class(self): called = [False] - class test(object): + class test: def __str__(self): called[0] = True return 'STR!!' @@ -837,14 +834,14 @@ def test_pysetitem(self): def test_pygetattr(self): lua_func = self.lua.eval('function(x) return x.ATTR end') - class test(object): + class test: def __init__(self): self.ATTR = 5 self.assertEqual(test().ATTR, lua_func(test())) def test_pysetattr(self): lua_func = self.lua.eval('function(x) x.ATTR = 123 end') - class test(object): + class test: def __init__(self): self.ATTR = 5 t = test() @@ -943,7 +940,7 @@ def attr_filter(obj, name, setting): lua = self.lupa.LuaRuntime(attribute_filter=attr_filter) function = lua.eval('function(obj) return obj.__name__ end') - class X(object): + class X: a = 0 a1 = 1 _a = 2 @@ -1049,14 +1046,14 @@ def test_pysetitem(self): def test_pygetattr(self): lua_func = self.lua.eval('function(x) return x.ATTR end') - class test(object): + class test: def __init__(self): self.ATTR = 5 self.assertEqual(test().ATTR, lua_func(test())) def test_pysetattr(self): lua_func = self.lua.eval('function(x) x.ATTR = 123 end') - class test(object): + class test: def __init__(self): self.ATTR = 5 t = test() @@ -1078,7 +1075,7 @@ def test_call_str_py(self): def test_call_str_class(self): called = [False] - class test(object): + class test: def __str__(self): called[0] = True return 'STR!!' @@ -1100,13 +1097,13 @@ def tearDown(self): self.lua = None gc.collect() - class X(object): + class X: a = 0 a1 = 1 _a = 2 __a = 3 - class Y(object): + class Y: a = 0 a1 = 1 _a = 2 @@ -1282,7 +1279,7 @@ def test_pyobject_wrapping_callable(self): lua_type = self.lua.eval('type') lua_get_call = self.lua.eval('function(obj) return getmetatable(obj).__call end') - class Callable(object): + class Callable: def __call__(self): pass def __getitem__(self, item): pass @@ -1293,7 +1290,7 @@ def test_pyobject_wrapping_getitem(self): lua_type = self.lua.eval('type') lua_get_index = self.lua.eval('function(obj) return getmetatable(obj).__index end') - class GetItem(object): + class GetItem: def __getitem__(self, item): pass self.assertEqual('userdata', lua_type(GetItem())) @@ -1303,7 +1300,7 @@ def test_pyobject_wrapping_getattr(self): lua_type = self.lua.eval('type') lua_get_index = self.lua.eval('function(obj) return getmetatable(obj).__index end') - class GetAttr(object): + class GetAttr: pass self.assertEqual('userdata', lua_type(GetAttr())) @@ -2234,7 +2231,7 @@ def setUp(self): self.lua = self.lupa.LuaRuntime(unpack_returned_tuples=True) - class C(object): + class C: def __init__(self, x): self.x = int(x) @@ -2364,19 +2361,19 @@ def func_3(x, y, z='default'): return ("x=%s, y=%s, z=%s" % (x, y, z)) -class MyCls_1(object): +class MyCls_1: @lupa.unpacks_lua_table_method def meth(self, x): return ("x=%s" % (x,)) -class MyCls_2(object): +class MyCls_2: @lupa.unpacks_lua_table_method def meth(self, x, y): return ("x=%s, y=%s" % (x, y)) -class MyCls_3(object): +class MyCls_3: @lupa.unpacks_lua_table_method def meth(self, x, y, z='default'): return ("x=%s, y=%s, z=%s" % (x, y, z)) @@ -2520,11 +2517,7 @@ class NoEncodingMethodKwargsDecoratorTest(MethodKwargsDecoratorTest): ################################################################################ # tests for the FastRLock implementation -try: - from thread import start_new_thread, get_ident -except ImportError: - # Python 3? - from _thread import start_new_thread, get_ident +from _thread import start_new_thread, get_ident def _wait(): @@ -2552,7 +2545,7 @@ def setUp(self): def tearDown(self): gc.collect() - class Bunch(object): + class Bunch: """ A bunch of threads. """ diff --git a/setup.py b/setup.py index c62ce034..1667ab77 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import glob import os import os.path