Skip to content

Commit 03a9c7e

Browse files
authored
Enable UP ruff checks and fix resulting warnings. NFC (#24198)
1 parent 1d262cc commit 03a9c7e

24 files changed

+48
-42
lines changed

emcc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ def run(args):
535535
# read response files very early on
536536
try:
537537
args = substitute_response_files(args)
538-
except IOError as e:
538+
except OSError as e:
539539
exit_with_error(e)
540540

541541
if '--help' in args:

emrun.py

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
# University of Illinois/NCSA Open Source License. Both these licenses can be
55
# found in the LICENSE file.
66

7+
# This file needs to run on older version of python too (even python 2!) so
8+
# suppress these upgrade warnings:
9+
# ruff: noqa: UP015, UP024, UP021, UP025
10+
711
"""emrun: Implements machinery that allows running a .html page as if it was a
812
standard executable file.
913

emsymbolizer.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Error(BaseException):
3131

3232

3333
# Class to treat location info in a uniform way across information sources.
34-
class LocationInfo(object):
34+
class LocationInfo:
3535
def __init__(self, source=None, line=0, column=0, func=None):
3636
self.source = source
3737
self.line = line
@@ -98,8 +98,8 @@ def get_sourceMappingURL_section(module):
9898
return None
9999

100100

101-
class WasmSourceMap(object):
102-
class Location(object):
101+
class WasmSourceMap:
102+
class Location:
103103
def __init__(self, source=None, line=0, column=0, func=None):
104104
self.source = source
105105
self.line = line

pyproject.toml

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[project]
2+
requires-python = ">=3.8"
3+
14
[tool.ruff]
25
exclude = [
36
"./cache/",
@@ -22,6 +25,7 @@ lint.select = [
2225
"PERF",
2326
"PIE",
2427
"PL",
28+
"UP",
2529
"W",
2630
"YTT",
2731
]
@@ -42,6 +46,9 @@ lint.ignore = [
4246
"PLW0603",
4347
"PLW1510",
4448
"PLW2901",
49+
"UP030", # TODO
50+
"UP031", # TODO
51+
"UP032", # TODO
4552
]
4653
lint.per-file-ignores."emrun.py" = [ "PLE0704" ]
4754
lint.per-file-ignores."tools/ports/*.py" = [ "ARG001", "ARG005" ]

requirements-dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
coverage[toml]==6.5
88
mypy==1.14
9-
ruff==0.11.4
9+
ruff==0.11.7
1010
types-requests==2.32.0.20241016
1111
unittest-xml-reporting==3.2.0
1212

site/source/get_api_items.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def addapiitems(matchobj):
6565
filepath = api_reference_directory + file
6666
print(file)
6767
# open file
68-
with open(filepath, 'r') as infile:
68+
with open(filepath) as infile:
6969
for line in infile:
7070
# parse line for API items
7171
re.sub(r'^\.\.\s+((\w+)\:(\w+)\:\:(.*))', addapiitems, line)

site/source/get_wiki.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def errorhandler(func, path, exc_info):
5757
try:
5858
shutil.rmtree(output_dir, ignore_errors=False, onerror=errorhandler)
5959
print('Old wiki clone removed')
60-
except IOError:
60+
except OSError:
6161
print('No directory to clean found')
6262

6363

system/bin/sdl-config.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python3
22

3-
from __future__ import print_function
43
import sys
54

65
print('emscripten sdl-config called with', ' '.join(sys.argv), file=sys.stderr)

test/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2079,7 +2079,7 @@ def send_head(self):
20792079
try:
20802080
fsize = os.path.getsize(path)
20812081
f = open(path, 'rb')
2082-
except IOError:
2082+
except OSError:
20832083
self.send_error(404, f'File not found {path}')
20842084
return None
20852085
self.send_response(206)

test/jsrun.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def run_js(filename, engine, args=None,
108108
input=input,
109109
cwd=cwd,
110110
timeout=timeout,
111-
universal_newlines=True)
111+
text=True)
112112
except Exception:
113113
# the failure may be because the engine is not present. show the proper
114114
# error in that case

test/parallel_testsuite.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def combine_results(self, result, buffered_results):
9595
return result
9696

9797

98-
class BufferedParallelTestResult():
98+
class BufferedParallelTestResult:
9999
"""A picklable struct used to communicate test results across processes
100100
101101
Fulfills the interface for unittest.TestResult
@@ -152,7 +152,7 @@ def addError(self, test, err):
152152
self.buffered_result = BufferedTestError(test, err)
153153

154154

155-
class BufferedTestBase():
155+
class BufferedTestBase:
156156
"""Abstract class that holds test result data, split by type of result."""
157157
def __init__(self, test, err=None):
158158
self.test = test
@@ -216,7 +216,7 @@ def updateResult(self, result):
216216
result.addUnexpectedSuccess(self.test)
217217

218218

219-
class FakeTraceback():
219+
class FakeTraceback:
220220
"""A fake version of a traceback object that is picklable across processes.
221221
222222
Python's traceback objects contain hidden stack information that isn't able
@@ -235,14 +235,14 @@ def __init__(self, tb):
235235
self.tb_lasti = tb.tb_lasti
236236

237237

238-
class FakeFrame():
238+
class FakeFrame:
239239
def __init__(self, f):
240240
self.f_code = FakeCode(f.f_code)
241241
# f.f_globals is not picklable, not used in stack traces, and needs to be iterable
242242
self.f_globals = []
243243

244244

245-
class FakeCode():
245+
class FakeCode:
246246
def __init__(self, co):
247247
self.co_filename = co.co_filename
248248
self.co_name = co.co_name

test/test_benchmark.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
EMTEST_BENCHMARKERS = os.getenv('EMTEST_BENCHMARKERS', 'clang,v8,v8-lto,v8-ctors')
5757

5858

59-
class Benchmarker():
59+
class Benchmarker:
6060
# Whether to record statistics. Set by SizeBenchmarker.
6161
record_stats = False
6262

test/test_browser.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# coding=utf-8
21
# Copyright 2013 The Emscripten Authors. All rights reserved.
32
# Emscripten is available under two separate licenses, the MIT license and the
43
# University of Illinois/NCSA Open Source License. Both these licenses can be
@@ -242,7 +241,7 @@ def proxy_to_worker(self):
242241
def require_jspi(self):
243242
if not is_chrome():
244243
self.skipTest(f'Current browser ({EMTEST_BROWSER}) does not support JSPI. Only chromium-based browsers ({CHROMIUM_BASED_BROWSERS}) support JSPI today.')
245-
super(browser, self).require_jspi()
244+
super().require_jspi()
246245

247246
def post_manual_reftest(self):
248247
assert os.path.exists('reftest.js')

test/test_other.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# coding=utf-8
21
# Copyright 2013 The Emscripten Authors. All rights reserved.
32
# Emscripten is available under two separate licenses, the MIT license and the
43
# University of Illinois/NCSA Open Source License. Both these licenses can be
@@ -6710,7 +6709,7 @@ def test_create_readonly(self):
67106709
def test_embed_file_large(self):
67116710
# If such long files are encoded on one line,
67126711
# they overflow the interpreter's limit
6713-
large_size = int(1500000)
6712+
large_size = 1500000
67146713
create_file('large.txt', 'x' * large_size)
67156714
create_file('src.c', r'''
67166715
#include <stdio.h>

test/test_sockets.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def clean_processes(processes):
4141
pass
4242

4343

44-
class WebsockifyServerHarness():
44+
class WebsockifyServerHarness:
4545
def __init__(self, filename, args, listen_port, do_server_check=True):
4646
self.processes = []
4747
self.filename = filename
@@ -81,7 +81,7 @@ def __enter__(self):
8181
proxy_sock = socket.create_connection(('localhost', self.listen_port), timeout=1)
8282
proxy_sock.close()
8383
break
84-
except IOError:
84+
except OSError:
8585
time.sleep(1)
8686
else:
8787
clean_processes(self.processes)
@@ -100,7 +100,7 @@ def __exit__(self, *args, **kwargs):
100100
clean_processes(self.processes)
101101

102102

103-
class CompiledServerHarness():
103+
class CompiledServerHarness:
104104
def __init__(self, filename, args, listen_port):
105105
self.processes = []
106106
self.filename = filename
@@ -134,7 +134,7 @@ def __exit__(self, *args, **kwargs):
134134

135135

136136
# Executes a native executable server process
137-
class BackgroundServerProcess():
137+
class BackgroundServerProcess:
138138
def __init__(self, args):
139139
self.processes = []
140140
self.args = args

tools/building.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ def move_to_safe_7bit_ascii_filename(filename):
677677

678678
# Print input file (long wall of text!)
679679
if DEBUG == 2 and (proc.returncode != 0 or (len(proc.stderr.strip()) > 0 and closure_warnings['enabled'])):
680-
input_file = open(filename, 'r').read().splitlines()
680+
input_file = open(filename).read().splitlines()
681681
for i in range(len(input_file)):
682682
sys.stderr.write(f'{i + 1}: {input_file[i]}\n')
683683

tools/experimental/reproduceriter.py

-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@
108108
109109
'''
110110

111-
from __future__ import print_function
112111
import os
113112
import re
114113
import sys

tools/file_packager.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ def has_hidden_attribute(filepath):
158158
return False
159159

160160
try:
161-
attrs = ctypes.windll.kernel32.GetFileAttributesW(
162-
u'%s' % filepath)
161+
attrs = ctypes.windll.kernel32.GetFileAttributesW(filepath)
163162
assert attrs != -1
164163
result = bool(attrs & 2)
165164
except Exception:
@@ -372,7 +371,7 @@ def main(): # noqa: C901, PLR0912, PLR0915
372371
# read response files very early on
373372
try:
374373
args = substitute_response_files(sys.argv[1:])
375-
except IOError as e:
374+
except OSError as e:
376375
shared.exit_with_error(e)
377376

378377
if '--help' in args:

tools/gen_struct_info.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python3
2-
# coding=utf-8
32
# Copyright 2013 The Emscripten Authors. All rights reserved.
43
# Emscripten is available under two separate licenses, the MIT license and the
54
# University of Illinois/NCSA Open Source License. Both these licenses can be
@@ -336,7 +335,7 @@ def inspect_code(headers, cflags):
336335
def parse_json(path):
337336
header_files = []
338337

339-
with open(path, 'r') as stream:
338+
with open(path) as stream:
340339
# Remove comments before loading the JSON.
341340
data = json.loads(re.sub(r'//.*\n', '', stream.read()))
342341

tools/response_file.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def read_response_file(response_filename):
6868
response_filename = response_filename[1:]
6969

7070
if not os.path.exists(response_filename):
71-
raise IOError("response file not found: %s" % response_filename)
71+
raise OSError("response file not found: %s" % response_filename)
7272

7373
# Guess encoding based on the file suffix
7474
components = os.path.basename(response_filename).split('.')

tools/shared.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import tempfile
2121

2222
# We depend on python 3.8 features
23-
if sys.version_info < (3, 8):
23+
if sys.version_info < (3, 8): # noqa: UP036
2424
print(f'error: emscripten requires python 3.8 or above ({sys.executable} {sys.version})', file=sys.stderr)
2525
sys.exit(1)
2626

tools/system_libs.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ def get_default_variation(cls, **kwargs):
736736

737737
@classmethod
738738
def variations(cls):
739-
combos = super(MTLibrary, cls).variations()
739+
combos = super().variations()
740740

741741
# These are mutually exclusive, only one flag will be set at any give time.
742742
return [combo for combo in combos if not combo['is_mt'] or not combo['is_ww']]
@@ -1406,7 +1406,7 @@ def can_use(self):
14061406
# EMCC_FORCE_STDLIBS can have a similar effect of forcing all libraries.
14071407
# In both cases, the build is not one that is hyper-focused on code size,
14081408
# and so optz is not that important.
1409-
return super(libc_optz, self).can_use() and settings.SHRINK_LEVEL >= 2 and \
1409+
return super().can_use() and settings.SHRINK_LEVEL >= 2 and \
14101410
not settings.LINKABLE and not os.environ.get('EMCC_FORCE_STDLIBS')
14111411

14121412

@@ -1420,7 +1420,7 @@ def get_files(self):
14201420
filenames=['vfprintf.c'])
14211421

14221422
def can_use(self):
1423-
return super(libprintf_long_double, self).can_use() and settings.PRINTF_LONG_DOUBLE
1423+
return super().can_use() and settings.PRINTF_LONG_DOUBLE
14241424

14251425

14261426
class libwasm_workers(DebugLibrary):
@@ -1496,7 +1496,7 @@ def get_files(self):
14961496
filenames=LIBC_SOCKETS)
14971497

14981498
def can_use(self):
1499-
return super(libsockets, self).can_use() and not settings.PROXY_POSIX_SOCKETS
1499+
return super().can_use() and not settings.PROXY_POSIX_SOCKETS
15001500

15011501

15021502
class libsockets_proxy(MTLibrary):
@@ -1508,7 +1508,7 @@ def get_files(self):
15081508
return [utils.path_from_root('system/lib/websocket/websocket_to_posix_socket.c')]
15091509

15101510
def can_use(self):
1511-
return super(libsockets_proxy, self).can_use() and settings.PROXY_POSIX_SOCKETS
1511+
return super().can_use() and settings.PROXY_POSIX_SOCKETS
15121512

15131513

15141514
class crt1(MuslInternalLibrary):
@@ -2240,7 +2240,7 @@ def get_files(self):
22402240
return files
22412241

22422242
def can_use(self):
2243-
return super(libstandalonewasm, self).can_use() and settings.STANDALONE_WASM
2243+
return super().can_use() and settings.STANDALONE_WASM
22442244

22452245

22462246
class libjsmath(Library):
@@ -2250,7 +2250,7 @@ class libjsmath(Library):
22502250
src_files = ['jsmath.c']
22512251

22522252
def can_use(self):
2253-
return super(libjsmath, self).can_use() and settings.JS_MATH
2253+
return super().can_use() and settings.JS_MATH
22542254

22552255

22562256
class libstubs(DebugLibrary):

tools/wasm-sourcemap.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,10 @@ def build_sourcemap(entries, code_section_offset, options):
313313
if collect_sources:
314314
load_name = prefixes.load.resolve(file_name)
315315
try:
316-
with open(load_name, 'r') as infile:
316+
with open(load_name) as infile:
317317
source_content = infile.read()
318318
sources_content.append(source_content)
319-
except IOError:
319+
except OSError:
320320
print('Failed to read source: %s' % load_name)
321321
sources_content.append(None)
322322
else:

tools/webidl_binder.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Emscripten is available under two separate licenses, the MIT license and the
33
# University of Illinois/NCSA Open Source License. Both these licenses can be
44
# found in the LICENSE file.
5+
# noqa: UP035
56

67
"""WebIDL binder
78

0 commit comments

Comments
 (0)