File: py12_recursion_PR19.diff

package info (click to toggle)
py-ubjson 0.16.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 464 kB
  • sloc: ansic: 1,992; python: 1,408; sh: 6; makefile: 5
file content (133 lines) | stat: -rw-r--r-- 4,683 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
Description: python 3.12 compatibility
 https://github.com/python/cpython/issues/112282
Forwarded: https://github.com/Iotic-Labs/py-ubjson/pull/19
--- a/setup.py
+++ b/setup.py
@@ -28,17 +28,17 @@
     use_setuptools()
     from setuptools import setup  # pylint: disable=ungrouped-imports
 
-from distutils.core import Extension
-from distutils.command.build_ext import build_ext
-from distutils.errors import CCompilerError
-from distutils.errors import DistutilsPlatformError, DistutilsExecError
+from distutils.core import Extension  # pylint: disable=import-error
+from distutils.command.build_ext import build_ext  # pylint: disable=import-error
+from distutils.errors import CCompilerError  # pylint: disable=import-error
+from distutils.errors import DistutilsPlatformError, DistutilsExecError  # pylint: disable=import-error
 
 from ubjson import __version__ as version
 
 
 def load_description(filename):
     script_dir = os.path.abspath(os.path.dirname(__file__))
-    with open(os.path.join(script_dir, filename), 'r') as infile:
+    with open(os.path.join(script_dir, filename), 'r') as infile:  # pylint: disable=unspecified-encoding
         return infile.read()
 
 
@@ -113,6 +113,10 @@
         'Programming Language :: Python :: 3.6',
         'Programming Language :: Python :: 3.7',
         'Programming Language :: Python :: 3.8',
+        'Programming Language :: Python :: 3.9',
+        'Programming Language :: Python :: 3.10',
+        'Programming Language :: Python :: 3.11',
+        'Programming Language :: Python :: 3.12',
         'Topic :: Software Development :: Libraries',
         'Topic :: Software Development :: Libraries :: Python Modules'
     ]
--- a/test/test.py
+++ b/test/test.py
@@ -13,7 +13,7 @@
 # limitations under the License.
 
 
-from sys import version_info, getrecursionlimit, setrecursionlimit
+from sys import version_info, getrecursionlimit
 from functools import partial
 from io import BytesIO, SEEK_END
 from unittest import TestCase, skipUnless
@@ -464,23 +464,18 @@
         return (self.assertRaisesRegexp if PY2 else self.assertRaisesRegex)(*args, **kwargs)
 
     def test_recursion(self):
-        old_limit = getrecursionlimit()
-        setrecursionlimit(200)
-        try:
-            obj = current = []
-            for _ in range(getrecursionlimit() * 2):
-                new_list = []
-                current.append(new_list)
-                current = new_list
-
-            with self.assert_raises_regex(RuntimeError, 'recursion'):
-                self.ubjdumpb(obj)
-
-            raw = ARRAY_START * (getrecursionlimit() * 2)
-            with self.assert_raises_regex(RuntimeError, 'recursion'):
-                self.ubjloadb(raw)
-        finally:
-            setrecursionlimit(old_limit)
+        obj = current = []
+        for _ in range(getrecursionlimit() * 30):
+            new_list = []
+            current.append(new_list)
+            current = new_list
+
+        with self.assert_raises_regex(RuntimeError, 'recursion'):
+            self.ubjdumpb(obj)
+
+        raw = ARRAY_START * (getrecursionlimit() * 30)
+        with self.assert_raises_regex(RuntimeError, 'recursion'):
+            self.ubjloadb(raw)
 
     def test_encode_default(self):
         def default(obj):
--- a/ubjson/__main__.py
+++ b/ubjson/__main__.py
@@ -67,7 +67,7 @@
 specified, output goes to stdout.""", file=stderr)
         return 1
 
-    do_from_json = (argv[1] == 'fromjson')
+    do_from_json = argv[1] == 'fromjson'
     in_file = out_file = None
     try:
         # input
@@ -75,6 +75,7 @@
             in_stream = stdin if do_from_json else STDIN_RAW
         else:
             try:
+                # pylint: disable=consider-using-with
                 in_stream = in_file = open(argv[2], 'r' if do_from_json else 'rb')
             except IOError as ex:
                 __error('Failed to open input file for reading: %s' % ex)
@@ -84,6 +85,7 @@
             out_stream = STDOUT_RAW if do_from_json else stdout
         else:
             try:
+                # pylint: disable=unspecified-encoding,consider-using-with
                 out_stream = out_file = open(argv[3], 'wb' if do_from_json else 'w')
             except IOError as ex:
                 __error('Failed to open output file for writing: %s' % ex)
@@ -98,6 +100,8 @@
         if out_file:
             out_file.close()
 
+    return 0
+
 
 if __name__ == "__main__":
     exit(main())
--- a/ubjson/compat.py
+++ b/ubjson/compat.py
@@ -42,7 +42,7 @@
 
 from sys import stderr, stdout, stdin, version_info
 
-PY2 = (version_info[0] == 2)
+PY2 = version_info[0] == 2
 
 if PY2:
     # pylint: disable=undefined-variable