all: Go back to using default ruff quote style.

Commit dc2fcfcc55 seems to have accidentally
changed the ruff quote style to "preserve", instead of keeping it at the
default which is "double".

Put it back to the default and update relevant .py files with this rule.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2025-07-22 22:58:52 +10:00
parent 6a4306a0df
commit 7729e80fdd
16 changed files with 45 additions and 46 deletions

View file

@ -68,4 +68,3 @@ mccabe.max-complexity = 40
# repl_: not real python files
# viper_args: uses f(*)
exclude = ["tests/basics/*.py", "tests/*/repl_*.py", "tests/micropython/viper_args.py"]
quote-style = "preserve"

View file

@ -5,5 +5,5 @@ cause: MicroPython is optimised for code space.
workaround: Always use balanced braces and brackets in expressions inside f-strings
"""
print(f'{"hello { world"}')
print(f'{"hello ] world"}')
print(f"{'hello { world'}")
print(f"{'hello ] world'}")

View file

@ -28,7 +28,7 @@ l.pop()
# Try to compress. This will try to allocate a large window and fail.
try:
g.write('test')
g.write("test")
except MemoryError:
print("MemoryError")

View file

@ -86,7 +86,7 @@ except ValueError:
# incomplete array declaration
try:
my_print(json.loads('[0,'))
my_print(json.loads("[0,"))
except ValueError:
print("ValueError")

View file

@ -13,4 +13,4 @@ print(json.loads("9111222333444555666"))
print(json.loads("-9111222333444555666"))
print(json.loads("9111222333444555666"))
print(json.loads("-9111222333444555666"))
print(json.loads("[\"9111222333444555666777\",9111222333444555666]"))
print(json.loads('["9111222333444555666777",9111222333444555666]'))

View file

@ -35,7 +35,7 @@ client_socket = DummySocket()
dtls_server_ctx = SSLContext(PROTOCOL_DTLS_SERVER)
dtls_server_ctx.verify_mode = CERT_NONE
dtls_server = dtls_server_ctx.wrap_socket(
server_socket, do_handshake_on_connect=False, client_id=b'dummy_client_id'
server_socket, do_handshake_on_connect=False, client_id=b"dummy_client_id"
)
print("Wrapped DTLS Server")

View file

@ -52,6 +52,6 @@ for function_name, function, test_vals in functions:
except ValueError as e:
ans = str(e)
# a tiny error in REPR_C value for 1.5204998778 causes a wrong rounded value
if is_REPR_C and function_name == 'erfc' and ans == "1.521":
if is_REPR_C and function_name == "erfc" and ans == "1.521":
ans = "1.52"
print("{}({:.4g}) = {}".format(function_name, value, ans))

View file

@ -7,39 +7,39 @@ try:
except TypeError:
# 2-argument version of next() not supported
# we are probably not at MICROPY_CONFIG_ROM_LEVEL_BASIC_FEATURES
print('SKIP')
print("SKIP")
raise SystemExit
# 1. test default visibility
from pkgstar_default import *
print('visibleFun' in globals())
print('VisibleClass' in globals())
print('_hiddenFun' in globals())
print('_HiddenClass' in globals())
print("visibleFun" in globals())
print("VisibleClass" in globals())
print("_hiddenFun" in globals())
print("_HiddenClass" in globals())
print(visibleFun())
# 2. test explicit visibility as defined by __all__ (as an array)
from pkgstar_all_array import *
print('publicFun' in globals())
print('PublicClass' in globals())
print('unlistedFun' in globals())
print('UnlistedClass' in globals())
print('_privateFun' in globals())
print('_PrivateClass' in globals())
print("publicFun" in globals())
print("PublicClass" in globals())
print("unlistedFun" in globals())
print("UnlistedClass" in globals())
print("_privateFun" in globals())
print("_PrivateClass" in globals())
print(publicFun())
# test dynamic import as used in asyncio
print('dynamicFun' in globals())
print("dynamicFun" in globals())
print(dynamicFun())
# 3. test explicit visibility as defined by __all__ (as an tuple)
from pkgstar_all_tuple import *
print('publicFun2' in globals())
print('PublicClass2' in globals())
print('unlistedFun2' in globals())
print('UnlistedClass2' in globals())
print("publicFun2" in globals())
print("PublicClass2" in globals())
print("unlistedFun2" in globals())
print("UnlistedClass2" in globals())
print(publicFun2())
# 4. test reporting of missing entries in __all__

View file

@ -1,4 +1,4 @@
__all__ = ['publicFun', 'PublicClass', 'dynamicFun']
__all__ = ["publicFun", "PublicClass", "dynamicFun"]
# Definitions below should always be imported by a star import

View file

@ -1,4 +1,4 @@
__all__ = ('existingFun', 'missingFun')
__all__ = ("existingFun", "missingFun")
def existingFun():

View file

@ -1,4 +1,4 @@
__all__ = ('publicFun2', 'PublicClass2')
__all__ = ("publicFun2", "PublicClass2")
# Definitions below should always be imported by a star import

View file

@ -16,7 +16,7 @@ import threading
import tempfile
# Maximum time to run a single test, in seconds.
TEST_TIMEOUT = float(os.environ.get('MICROPY_TEST_TIMEOUT', 30))
TEST_TIMEOUT = float(os.environ.get("MICROPY_TEST_TIMEOUT", 30))
# See stackoverflow.com/questions/2632199: __file__ nor sys.argv[0]
# are guaranteed to always work, this one should though.
@ -411,7 +411,7 @@ def run_micropython(pyb, args, test_file, test_file_abspath, is_special=False):
def send_get(what):
# Detect {\x00} pattern and convert to ctrl-key codes.
ctrl_code = lambda m: bytes([int(m.group(1))])
what = re.sub(rb'{\\x(\d\d)}', ctrl_code, what)
what = re.sub(rb"{\\x(\d\d)}", ctrl_code, what)
os.write(master, what)
return get()

View file

@ -309,7 +309,7 @@ def do_filesystem_recursive_rm(state, path, args):
os.path.join(r_cwd, path) if not os.path.isabs(path) else path
)
if isinstance(state.transport, SerialTransport) and abs_path.startswith(
f'{SerialTransport.fs_hook_mount}/'
f"{SerialTransport.fs_hook_mount}/"
):
raise CommandError(
f"rm -r not permitted on {SerialTransport.fs_hook_mount} directory"
@ -335,11 +335,11 @@ def do_filesystem_recursive_rm(state, path, args):
def human_size(size, decimals=1):
for unit in ['B', 'K', 'M', 'G', 'T']:
if size < 1024.0 or unit == 'T':
for unit in ["B", "K", "M", "G", "T"]:
if size < 1024.0 or unit == "T":
break
size /= 1024.0
return f"{size:.{decimals}f}{unit}" if unit != 'B' else f"{int(size)}"
return f"{size:.{decimals}f}{unit}" if unit != "B" else f"{int(size)}"
def do_filesystem_tree(state, path, args):

View file

@ -598,7 +598,7 @@ def main():
cmd == "fs"
and len(command_args) >= 1
and command_args[0] in ("ls", "tree")
and sum(1 for a in command_args if not a.startswith('-')) == 1
and sum(1 for a in command_args if not a.startswith("-")) == 1
):
command_args.append("")

View file

@ -110,7 +110,7 @@ def _is_disconnect_exception(exception):
False otherwise.
"""
if isinstance(exception, OSError):
if hasattr(exception, 'args') and len(exception.args) > 0:
if hasattr(exception, "args") and len(exception.args) > 0:
# IO error, device disappeared
if exception.args[0] == 5:
return True

View file

@ -1521,31 +1521,31 @@ def parse_linkerscript(source):
symbols = {}
LINE_REGEX = re.compile(
r'^(?P<weak>PROVIDE\()?' # optional weak marker start
r'(?P<symbol>[a-zA-Z_]\w*)' # symbol name
r'=0x(?P<address>[\da-fA-F]{1,8})*' # symbol address
r'(?(weak)\));$', # optional weak marker end and line terminator
r"^(?P<weak>PROVIDE\()?" # optional weak marker start
r"(?P<symbol>[a-zA-Z_]\w*)" # symbol name
r"=0x(?P<address>[\da-fA-F]{1,8})*" # symbol address
r"(?(weak)\));$", # optional weak marker end and line terminator
re.ASCII,
)
inside_comment = False
for line in (line.strip() for line in source.readlines()):
if line.startswith('/*') and not inside_comment:
if not line.endswith('*/'):
if line.startswith("/*") and not inside_comment:
if not line.endswith("*/"):
inside_comment = True
continue
if inside_comment:
if line.endswith('*/'):
if line.endswith("*/"):
inside_comment = False
continue
if line.startswith('//'):
if line.startswith("//"):
continue
match = LINE_REGEX.match(''.join(line.split()))
match = LINE_REGEX.match("".join(line.split()))
if not match:
continue
tokens = match.groupdict()
symbol = tokens['symbol']
address = int(tokens['address'], 16)
symbol = tokens["symbol"]
address = int(tokens["address"], 16)
if symbol in symbols:
raise ValueError(f"Symbol {symbol} already defined")
symbols[symbol] = address