Skip to content

Commit 214a352

Browse files
authored
fix[ux]: replace standard strings with f-strings (#3953)
also add flake8 FS003 rule
1 parent 39b46ca commit 214a352

File tree

18 files changed

+24
-24
lines changed

18 files changed

+24
-24
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ black:
3131
black -C -t py311 vyper/ tests/ setup.py --force-exclude=vyper/version.py
3232

3333
flake8: black
34-
flake8 vyper/ tests/
34+
flake8 --enable-extensions=FS003 vyper/ tests/
3535

3636
isort: black
3737
isort vyper/ tests/ setup.py

tests/functional/builtins/folding/test_keccak_sha.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from tests.utils import parse_and_fold
66

7-
alphabet = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&()*+,-./:;<=>?@[]^_`{|}~' # NOQA: E501
7+
alphabet = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&()*+,-./:;<=>?@[]^_`{|}~' # NOQA: E501, FS003
88

99

1010
@pytest.mark.fuzzing

tests/functional/codegen/test_selector_table_stability.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_dense_jumptable_stability():
1414

1515
# test that the selector table data is stable across different runs
1616
# (xdist should provide different PYTHONHASHSEEDs).
17-
expected_asm = """{ DATA _sym_BUCKET_HEADERS b\'\\x0bB\' _sym_bucket_0 b\'\\n\' b\'+\\x8d\' _sym_bucket_1 b\'\\x0c\' b\'\\x00\\x85\' _sym_bucket_2 b\'\\x08\' } { DATA _sym_bucket_1 b\'\\xd8\\xee\\xa1\\xe8\' _sym_external 6 foo6()3639517672 b\'\\x05\' b\'\\xd2\\x9e\\xe0\\xf9\' _sym_external 0 foo0()3533627641 b\'\\x05\' b\'\\x05\\xf1\\xe0_\' _sym_external 2 foo2()99737695 b\'\\x05\' b\'\\x91\\t\\xb4{\' _sym_external 23 foo23()2433332347 b\'\\x05\' b\'np3\\x7f\' _sym_external 11 foo11()1852846975 b\'\\x05\' b\'&\\xf5\\x96\\xf9\' _sym_external 13 foo13()653629177 b\'\\x05\' b\'\\x04ga\\xeb\' _sym_external 14 foo14()73884139 b\'\\x05\' b\'\\x89\\x06\\xad\\xc6\' _sym_external 17 foo17()2298916294 b\'\\x05\' b\'\\xe4%\\xac\\xd1\' _sym_external 4 foo4()3827674321 b\'\\x05\' b\'yj\\x01\\xac\' _sym_external 7 foo7()2036990380 b\'\\x05\' b\'\\xf1\\xe6K\\xe5\' _sym_external 29 foo29()4058401765 b\'\\x05\' b\'\\xd2\\x89X\\xb8\' _sym_external 3 foo3()3532216504 b\'\\x05\' } { DATA _sym_bucket_2 b\'\\x06p\\xffj\' _sym_external 25 foo25()108068714 b\'\\x05\' b\'\\x964\\x99I\' _sym_external 24 foo24()2520029513 b\'\\x05\' b\'s\\x81\\xe7\\xc1\' _sym_external 10 foo10()1937893313 b\'\\x05\' b\'\\x85\\xad\\xc11\' _sym_external 28 foo28()2242756913 b\'\\x05\' b\'\\xfa"\\xb1\\xed\' _sym_external 5 foo5()4196577773 b\'\\x05\' b\'A\\xe7[\\x05\' _sym_external 22 foo22()1105681157 b\'\\x05\' b\'\\xd3\\x89U\\xe8\' _sym_external 1 foo1()3548993000 b\'\\x05\' b\'hL\\xf8\\xf3\' _sym_external 20 foo20()1749874931 b\'\\x05\' } { DATA _sym_bucket_0 b\'\\xee\\xd9\\x1d\\xe3\' _sym_external 9 foo9()4007206371 b\'\\x05\' b\'a\\xbc\\x1ch\' _sym_external 16 foo16()1639717992 b\'\\x05\' b\'\\xd3*\\xa7\\x0c\' _sym_external 21 foo21()3542787852 b\'\\x05\' b\'\\x18iG\\xd9\' _sym_external 19 foo19()409552857 b\'\\x05\' b\'\\n\\xf1\\xf9\\x7f\' _sym_external 18 foo18()183630207 b\'\\x05\' b\')\\xda\\xd7`\' _sym_external 27 foo27()702207840 b\'\\x05\' b\'2\\xf6\\xaa\\xda\' _sym_external 12 foo12()855026394 b\'\\x05\' b\'\\xbe\\xb5\\x05\\xf5\' _sym_external 15 foo15()3199534581 b\'\\x05\' b\'\\xfc\\xa7_\\xe6\' _sym_external 8 foo8()4238827494 b\'\\x05\' b\'\\x1b\\x12C8\' _sym_external 26 foo26()454181688 b\'\\x05\' } }""" # noqa: E501
17+
expected_asm = """{ DATA _sym_BUCKET_HEADERS b\'\\x0bB\' _sym_bucket_0 b\'\\n\' b\'+\\x8d\' _sym_bucket_1 b\'\\x0c\' b\'\\x00\\x85\' _sym_bucket_2 b\'\\x08\' } { DATA _sym_bucket_1 b\'\\xd8\\xee\\xa1\\xe8\' _sym_external 6 foo6()3639517672 b\'\\x05\' b\'\\xd2\\x9e\\xe0\\xf9\' _sym_external 0 foo0()3533627641 b\'\\x05\' b\'\\x05\\xf1\\xe0_\' _sym_external 2 foo2()99737695 b\'\\x05\' b\'\\x91\\t\\xb4{\' _sym_external 23 foo23()2433332347 b\'\\x05\' b\'np3\\x7f\' _sym_external 11 foo11()1852846975 b\'\\x05\' b\'&\\xf5\\x96\\xf9\' _sym_external 13 foo13()653629177 b\'\\x05\' b\'\\x04ga\\xeb\' _sym_external 14 foo14()73884139 b\'\\x05\' b\'\\x89\\x06\\xad\\xc6\' _sym_external 17 foo17()2298916294 b\'\\x05\' b\'\\xe4%\\xac\\xd1\' _sym_external 4 foo4()3827674321 b\'\\x05\' b\'yj\\x01\\xac\' _sym_external 7 foo7()2036990380 b\'\\x05\' b\'\\xf1\\xe6K\\xe5\' _sym_external 29 foo29()4058401765 b\'\\x05\' b\'\\xd2\\x89X\\xb8\' _sym_external 3 foo3()3532216504 b\'\\x05\' } { DATA _sym_bucket_2 b\'\\x06p\\xffj\' _sym_external 25 foo25()108068714 b\'\\x05\' b\'\\x964\\x99I\' _sym_external 24 foo24()2520029513 b\'\\x05\' b\'s\\x81\\xe7\\xc1\' _sym_external 10 foo10()1937893313 b\'\\x05\' b\'\\x85\\xad\\xc11\' _sym_external 28 foo28()2242756913 b\'\\x05\' b\'\\xfa"\\xb1\\xed\' _sym_external 5 foo5()4196577773 b\'\\x05\' b\'A\\xe7[\\x05\' _sym_external 22 foo22()1105681157 b\'\\x05\' b\'\\xd3\\x89U\\xe8\' _sym_external 1 foo1()3548993000 b\'\\x05\' b\'hL\\xf8\\xf3\' _sym_external 20 foo20()1749874931 b\'\\x05\' } { DATA _sym_bucket_0 b\'\\xee\\xd9\\x1d\\xe3\' _sym_external 9 foo9()4007206371 b\'\\x05\' b\'a\\xbc\\x1ch\' _sym_external 16 foo16()1639717992 b\'\\x05\' b\'\\xd3*\\xa7\\x0c\' _sym_external 21 foo21()3542787852 b\'\\x05\' b\'\\x18iG\\xd9\' _sym_external 19 foo19()409552857 b\'\\x05\' b\'\\n\\xf1\\xf9\\x7f\' _sym_external 18 foo18()183630207 b\'\\x05\' b\')\\xda\\xd7`\' _sym_external 27 foo27()702207840 b\'\\x05\' b\'2\\xf6\\xaa\\xda\' _sym_external 12 foo12()855026394 b\'\\x05\' b\'\\xbe\\xb5\\x05\\xf5\' _sym_external 15 foo15()3199534581 b\'\\x05\' b\'\\xfc\\xa7_\\xe6\' _sym_external 8 foo8()4238827494 b\'\\x05\' b\'\\x1b\\x12C8\' _sym_external 26 foo26()454181688 b\'\\x05\' } }""" # noqa: E501, FS003
1818
assert expected_asm in output["asm"]
1919

2020

tests/functional/examples/tokens/test_erc1155.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
CONTRACT_NAME = "TEST 1155"
88
CONTRACT_SYMBOL = "T1155"
99

10-
CONTRACT_URI = "https://mydomain.io/NFTdata/{id}"
11-
NEW_CONTRACT_URI = "https://mynewdomain.io/NFTdata/{id}"
10+
CONTRACT_URI = "https://mydomain.io/NFTdata/ID"
11+
NEW_CONTRACT_URI = "https://mynewdomain.io/NFTdata/ID"
1212
CONTRACT_METADATA_URI = "https://mydomain.io/NFTdata/collectionMetaData.json"
1313
NEW_CONTRACT_METADATA_URI = "https://mydomain.io/NFTdata/newCollectionMetaData.json"
1414

tests/functional/syntax/test_address_code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from vyper.exceptions import NamespaceCollision, StructureException, VyperException
1010

1111
# For reproducibility, use precompiled data of `hello: public(uint256)` using vyper 0.3.1
12-
PRECOMPILED_ABI = """[{"stateMutability": "view", "type": "function", "name": "hello", "inputs": [], "outputs": [{"name": "", "type": "uint256"}], "gas": 2460}]""" # noqa: E501
12+
PRECOMPILED_ABI = """[{"stateMutability": "view", "type": "function", "name": "hello", "inputs": [], "outputs": [{"name": "", "type": "uint256"}], "gas": 2460}]""" # noqa: E501, FS003
1313
PRECOMPILED_BYTECODE = """0x61004456600436101561000d57610035565b60046000601c376000513461003b576319ff1d2181186100335760005460e052602060e0f35b505b60006000fd5b600080fd5b61000461004403610004600039610004610044036000f3""" # noqa: E501
1414
PRECOMPILED_BYTECODE_RUNTIME = """0x600436101561000d57610035565b60046000601c376000513461003b576319ff1d2181186100335760005460e052602060e0f35b505b60006000fd5b600080fd""" # noqa: E501
1515
PRECOMPILED = bytes.fromhex(PRECOMPILED_BYTECODE_RUNTIME[2:])

vyper/ast/nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,7 @@ def _check_args(annotation, call_name):
13931393
# do the same thing as `validate_call_args`
13941394
# (can't be imported due to cyclic dependency)
13951395
if len(annotation.args) != 1:
1396-
raise ArgumentException("Invalid number of arguments to `{call_name}`:", self)
1396+
raise ArgumentException(f"Invalid number of arguments to `{call_name}`:", self)
13971397

13981398
# the annotation is a "function" call, e.g.
13991399
# `foo: public(constant(uint256))`

vyper/ast/pre_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def pre_parse(code: str) -> tuple[Settings, ModificationOffsets, dict, str]:
205205
raise StructureException("pragma evm-version specified twice!", start)
206206
evm_version = pragma.removeprefix("evm-version").strip()
207207
if evm_version not in EVM_VERSIONS:
208-
raise StructureException("Invalid evm version: `{evm_version}`", start)
208+
raise StructureException(f"Invalid evm version: `{evm_version}`", start)
209209
settings.evm_version = evm_version
210210
elif pragma.startswith("experimental-codegen"):
211211
if settings.experimental_codegen is not None:

vyper/builtins/functions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,8 +1658,8 @@ class _CreateBase(BuiltinFunctionT):
16581658

16591659
@process_inputs
16601660
def build_IR(self, expr, args, kwargs, context):
1661-
# errmsg something like "Cannot use {self._id} in pure fn"
1662-
context.check_is_not_constant("use {self._id}", expr)
1661+
# errmsg something like f"Cannot use {self._id} in pure fn"
1662+
context.check_is_not_constant(f"use {self._id}", expr)
16631663

16641664
should_use_create2 = "salt" in [kwarg.arg for kwarg in expr.keywords]
16651665

@@ -2277,7 +2277,7 @@ def build_IR(self, expr, args, kwargs, context):
22772277
method_id = method_id_int("log(string,bytes)")
22782278
schema = args_abi_t.selector_name().encode("utf-8")
22792279
if len(schema) > 32:
2280-
raise CompilerPanic("print signature too long: {schema}")
2280+
raise CompilerPanic(f"print signature too long: {schema}")
22812281

22822282
schema_t = StringT(len(schema))
22832283
schema_buf = context.new_internal_variable(schema_t)

vyper/cli/vyper_compile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ def compile_files(
284284
if storage_layout_paths:
285285
if len(storage_layout_paths) != len(input_files):
286286
raise ValueError(
287-
"provided {len(storage_layout_paths)} storage "
288-
"layouts, but {len(input_files)} source files"
287+
f"provided {len(storage_layout_paths)} storage "
288+
f"layouts, but {len(input_files)} source files"
289289
)
290290

291291
ret: dict[Any, Any] = {}

vyper/cli/vyper_json.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def get_inputs(input_dict: dict) -> dict[PurePath, Any]:
190190

191191
# some validation
192192
if not isinstance(value, dict):
193-
raise JSONError("invalid interface (must be a dictionary):\n{json.dumps(value)}")
193+
raise JSONError(f"invalid interface (must be a dictionary):\n{json.dumps(value)}")
194194
if "content" in value:
195195
if not isinstance(value["content"], str):
196196
raise JSONError(f"invalid 'content' (expected string):\n{json.dumps(value)}")
@@ -199,11 +199,11 @@ def get_inputs(input_dict: dict) -> dict[PurePath, Any]:
199199
raise JSONError(f"invalid 'abi' (expected list):\n{json.dumps(value)}")
200200
else:
201201
raise JSONError(
202-
"invalid interface (must contain either 'content' or 'abi'):\n{json.dumps(value)}"
202+
f"invalid interface (must contain either 'content' or 'abi'):\n{json.dumps(value)}"
203203
)
204204
if "content" in value and "abi" in value:
205205
raise JSONError(
206-
"invalid interface (found both 'content' and 'abi'):\n{json.dumps(value)}"
206+
f"invalid interface (found both 'content' and 'abi'):\n{json.dumps(value)}"
207207
)
208208

209209
ret[path] = value

0 commit comments

Comments
 (0)