File size: 32,263 Bytes
1600cd6 f4952b6 1600cd6 f4952b6 db2c7db 1600cd6 f4952b6 db2c7db f4952b6 1600cd6 f4952b6 db2c7db f4952b6 1600cd6 | 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 | {"case_id": "pat-annotate-literal-defaults-positive", "edits": [{"file": "src/tokens.py", "label": "signature of 'count_words'", "replace": "def count_words(text: str = \"\", unit: str = \"word\"):\n parts = text.split()\n if unit == \"word\":\n return len(parts)\n if unit == \"line\":\n return len(text.splitlines())\n return 0", "search": "def count_words(text=\"\", unit=\"word\"):\n parts = text.split()\n if unit == \"word\":\n return len(parts)\n if unit == \"line\":\n return len(text.splitlines())\n return 0"}, {"file": "tests/test_tokens.py", "label": "lock test 'test_count_words_parameters_keep_their_defaults' appended after 'test_summarize_follows_the_unit'", "replace": "def test_summarize_follows_the_unit() -> None:\n assert summarize(\"a b\", unit=\"word\") == 2\n assert count_lines(\"a\\nb\") == 2\n\n\ndef test_count_words_parameters_keep_their_defaults() -> None:\n \"\"\"Lock the annotations this pattern added and the defaults it had to leave alone.\"\"\"\n import inspect\n\n from src import tokens\n parameters = inspect.signature(tokens.count_words).parameters\n assert parameters['text'].annotation is str\n assert parameters['text'].default == ''\n assert parameters['unit'].annotation is str\n assert parameters['unit'].default == 'word'\n", "search": "def test_summarize_follows_the_unit() -> None:\n assert summarize(\"a b\", unit=\"word\") == 2\n assert count_lines(\"a\\nb\") == 2"}], "expect": "VERIFIED", "family": "typing", "intent_tags": ["annotate", "defaults", "types"], "language": "python", "min_assurance": 3, "note": "a module level function whose parameter has a literal default and no annotation", "pattern_id": "annotate-literal-defaults", "rule": "annotate-literal-defaults", "targets": ["src/tokens.py::count_words"]}
{"case_id": "pat-annotate-literal-defaults-negative", "edits": [], "expect": "REFUSED", "family": "typing", "intent_tags": ["annotate", "defaults", "types"], "language": "python", "min_assurance": 3, "note": "a module level function whose parameter has a literal default and no annotation", "pattern_id": "annotate-literal-defaults", "reason_code": "ALREADY_ANNOTATED", "rule": "annotate-literal-defaults", "targets": ["src/tokens.py::count_lines"]}
{"case_id": "pat-annotate-literal-defaults-coroutine-positive", "edits": [{"file": "src/asyncops.py", "label": "signature of 'render_page'", "replace": "async def render_page(url, width: int = 80):\n return str(url).ljust(width)", "search": "async def render_page(url, width=80):\n return str(url).ljust(width)"}, {"file": "tests/test_asyncops.py", "label": "lock test 'test_render_page_parameters_keep_their_defaults' appended after 'test_item_count_counts_items'", "replace": "def test_item_count_counts_items() -> None:\n assert asyncio.run(item_count([1, 2])) == 2\n\n\ndef test_render_page_parameters_keep_their_defaults() -> None:\n \"\"\"Lock the annotations this pattern added and the defaults it had to leave alone.\"\"\"\n import inspect\n\n from src import asyncops\n parameters = inspect.signature(asyncops.render_page).parameters\n assert parameters['width'].annotation is int\n assert parameters['width'].default == 80\n", "search": "def test_item_count_counts_items() -> None:\n assert asyncio.run(item_count([1, 2])) == 2"}], "expect": "VERIFIED", "family": "typing", "intent_tags": ["annotate", "defaults", "types"], "language": "python", "min_assurance": 3, "note": "a module level function whose parameter has a literal default and no annotation", "pattern_id": "annotate-literal-defaults", "rule": "annotate-literal-defaults", "targets": ["src/asyncops.py::render_page"]}
{"case_id": "pat-annotate-literal-defaults-coroutine-negative", "edits": [], "expect": "REFUSED", "family": "typing", "intent_tags": ["annotate", "defaults", "types"], "language": "python", "min_assurance": 3, "note": "a module level function whose parameter has a literal default and no annotation", "pattern_id": "annotate-literal-defaults", "reason_code": "ALREADY_ANNOTATED", "rule": "annotate-literal-defaults", "targets": ["src/asyncops.py::sized"]}
{"case_id": "pat-bare-assert-to-explicit-raise-positive", "edits": [{"file": "src/guards.py", "label": "explicit raise of 'open_ticket'", "replace": "def open_ticket(queue_name):\n if not queue_name:\n raise AssertionError(\"queue name is required\")\n return {\"queue\": queue_name, \"opened\": True}", "search": "def open_ticket(queue_name):\n assert queue_name, \"queue name is required\"\n return {\"queue\": queue_name, \"opened\": True}"}, {"file": "tests/test_guards.py", "label": "lock test 'test_open_ticket_raises_in_stead_of_asserting' appended after 'test_close_ticket_clears_the_flag'", "replace": "def test_close_ticket_clears_the_flag() -> None:\n closed = close_ticket(open_ticket(\"builds\"))\n assert closed[\"opened\"] is False\n with pytest.raises(AssertionError):\n close_ticket({\"queue\": \"\"})\n\n\ndef test_open_ticket_raises_in_stead_of_asserting() -> None:\n \"\"\"Lock the raise that replaced the assert, and the refusal the function still carries.\"\"\"\n import inspect\n\n from src import guards\n source = inspect.getsource(guards.open_ticket)\n assert 'raise AssertionError(' in source\n assert not [line for line in source.splitlines() if line.strip().startswith('assert ')]\n try:\n guards.open_ticket(\"\")\n except AssertionError as caught:\n assert \"queue name is required\" in str(caught)\n else:\n raise AssertionError('open_ticket accepted an argument its check rejects')\n", "search": "def test_close_ticket_clears_the_flag() -> None:\n closed = close_ticket(open_ticket(\"builds\"))\n assert closed[\"opened\"] is False\n with pytest.raises(AssertionError):\n close_ticket({\"queue\": \"\"})"}], "expect": "VERIFIED", "family": "contracts", "intent_tags": ["preconditions", "errors", "contracts"], "language": "python", "min_assurance": 3, "note": "a module level function whose first statement is an assert guarding its arguments", "pattern_id": "bare-assert-to-explicit-raise", "rule": "bare-assert-to-explicit-raise", "targets": ["src/guards.py::open_ticket"]}
{"case_id": "pat-bare-assert-to-explicit-raise-negative", "edits": [], "expect": "REFUSED", "family": "contracts", "intent_tags": ["preconditions", "errors", "contracts"], "language": "python", "min_assurance": 3, "note": "a module level function whose first statement is an assert guarding its arguments", "pattern_id": "bare-assert-to-explicit-raise", "reason_code": "NOT_THE_FIRST_STATEMENT", "rule": "bare-assert-to-explicit-raise", "targets": ["src/guards.py::close_ticket"]}
{"case_id": "pat-bare-assert-to-explicit-raise-coroutine-positive", "edits": [{"file": "src/asyncops.py", "label": "explicit raise of 'check_name'", "replace": "async def check_name(name):\n if not name:\n raise AssertionError()\n return name", "search": "async def check_name(name):\n assert name\n return name"}, {"file": "tests/test_asyncops.py", "label": "lock test 'test_check_name_raises_in_stead_of_asserting' appended after 'test_item_count_counts_items'", "replace": "def test_item_count_counts_items() -> None:\n assert asyncio.run(item_count([1, 2])) == 2\n\n\ndef test_check_name_raises_in_stead_of_asserting() -> None:\n \"\"\"Lock the raise that replaced the assert, and the refusal the function still carries.\"\"\"\n import inspect\n import asyncio\n\n from src import asyncops\n source = inspect.getsource(asyncops.check_name)\n assert 'raise AssertionError(' in source\n assert not [line for line in source.splitlines() if line.strip().startswith('assert ')]\n try:\n asyncio.run(asyncops.check_name(\"\"))\n except AssertionError as caught:\n pass\n else:\n raise AssertionError('check_name accepted an argument its check rejects')\n", "search": "def test_item_count_counts_items() -> None:\n assert asyncio.run(item_count([1, 2])) == 2"}], "expect": "VERIFIED", "family": "contracts", "intent_tags": ["preconditions", "errors", "contracts"], "language": "python", "min_assurance": 3, "note": "a module level function whose first statement is an assert guarding its arguments", "pattern_id": "bare-assert-to-explicit-raise", "rule": "bare-assert-to-explicit-raise", "targets": ["src/asyncops.py::check_name"]}
{"case_id": "pat-bare-assert-to-explicit-raise-coroutine-negative", "edits": [], "expect": "REFUSED", "family": "contracts", "intent_tags": ["preconditions", "errors", "contracts"], "language": "python", "min_assurance": 3, "note": "a module level function whose first statement is an assert guarding its arguments", "pattern_id": "bare-assert-to-explicit-raise", "reason_code": "NOT_THE_FIRST_STATEMENT", "rule": "bare-assert-to-explicit-raise", "targets": ["src/asyncops.py::check_after"]}
{"case_id": "pat-bare-except-to-narrow-exception-positive", "edits": [{"file": "src/retries.py", "label": "named handler of 'call_or_none'", "replace": "def call_or_none(source):\n try:\n return source.read()\n except Exception:\n return \"\"", "search": "def call_or_none(source):\n try:\n return source.read()\n except:\n return \"\""}, {"file": "tests/test_retries.py", "label": "lock test 'test_call_or_none_answers_named_exceptions' appended after 'test_call_or_none_falls_back_when_reading_fails'", "replace": "def test_call_or_none_falls_back_when_reading_fails() -> None:\n assert call_or_none(_BrokenSource()) == \"\"\n\n\ndef test_call_or_none_answers_named_exceptions() -> None:\n \"\"\"Lock the class every handler of this function now names.\"\"\"\n import inspect\n\n from src import retries\n source = inspect.getsource(retries.call_or_none)\n assert 'except Exception:' in source\n assert 'except:' not in source\n", "search": "def test_call_or_none_falls_back_when_reading_fails() -> None:\n assert call_or_none(_BrokenSource()) == \"\""}], "expect": "VERIFIED", "family": "contracts", "intent_tags": ["errors", "exceptions", "contracts"], "language": "python", "min_assurance": 3, "note": "a module level function with an except handler that names no exception class", "pattern_id": "bare-except-to-narrow-exception", "rule": "bare-except-to-narrow-exception", "targets": ["src/retries.py::call_or_none"]}
{"case_id": "pat-bare-except-to-narrow-exception-negative", "edits": [], "expect": "REFUSED", "family": "contracts", "intent_tags": ["errors", "exceptions", "contracts"], "language": "python", "min_assurance": 3, "note": "a module level function with an except handler that names no exception class", "pattern_id": "bare-except-to-narrow-exception", "reason_code": "NO_BARE_EXCEPT", "rule": "bare-except-to-narrow-exception", "targets": ["src/retries.py::call_or_note"]}
{"case_id": "pat-chain-to-registry-positive", "edits": [{"file": "src/registry.py", "label": "dispatch registry of 'render'", "replace": "def render(kind, item):\n handlers = {\"short\": format_short, \"long\": format_long, \"json\": format_json}\n handled = handlers.get(kind)\n if handled is None:\n raise ValueError(\"unsupported kind\")\n return handled(item)", "search": "def render(kind, item):\n if kind == \"short\":\n return format_short(item)\n elif kind == \"long\":\n return format_long(item)\n elif kind == \"json\":\n return format_json(item)\n else:\n raise ValueError(\"unsupported kind\")"}, {"file": "tests/test_registry.py", "label": "lock test 'test_render_dispatches_through_a_registry' appended after 'test_render_rejects_an_unknown_kind'", "replace": "def test_render_rejects_an_unknown_kind() -> None:\n with pytest.raises(ValueError):\n render(\"yaml\", 5)\n\n\ndef test_render_dispatches_through_a_registry() -> None:\n \"\"\"Lock the registry the chain became, and the answers the chain used to give.\"\"\"\n import inspect\n\n from src import registry\n source = inspect.getsource(registry.render)\n assert 'handlers = {' in source\n assert '\"short\": format_short' in source\n assert '\"long\": format_long' in source\n assert '\"json\": format_json' in source\n assert 'handlers.get(kind)' in source\n assert 'elif' not in source\n assert registry.render('short', \"\") == registry.format_short(\"\")\n assert registry.render('long', \"\") == registry.format_long(\"\")\n assert registry.render('json', \"\") == registry.format_json(\"\")\n try:\n registry.render('~no such kind~', \"\")\n except ValueError:\n pass\n else:\n raise AssertionError('render accepted a kind no branch carries')\n", "search": "def test_render_rejects_an_unknown_kind() -> None:\n with pytest.raises(ValueError):\n render(\"yaml\", 5)"}], "expect": "VERIFIED", "family": "shape", "intent_tags": ["dispatch", "registry", "extension"], "language": "python", "min_assurance": 3, "note": "a module level function that dispatches an if/elif chain of one name compared to text literals", "pattern_id": "chain-to-registry", "rule": "chain-to-registry", "targets": ["src/registry.py::render"]}
{"case_id": "pat-chain-to-registry-negative", "edits": [], "expect": "REFUSED", "family": "shape", "intent_tags": ["dispatch", "registry", "extension"], "language": "python", "min_assurance": 3, "note": "a module level function that dispatches an if/elif chain of one name compared to text literals", "pattern_id": "chain-to-registry", "reason_code": "BRANCH_SHAPE_MISMATCH", "rule": "chain-to-registry", "targets": ["src/registry.py::render_pair"]}
{"case_id": "pat-drop-unused-imports-positive", "edits": [{"file": "src/legacy.py", "label": "unread imports of 'src/legacy.py' removed", "replace": "", "search": "import json\n"}, {"file": "tests/test_legacy.py", "label": "lock test 'test_read_size_keeps_no_unread_imports' appended after 'test_note_path_names_the_file'", "replace": "def test_note_path_names_the_file() -> None:\n assert Path(note_path(\"one\")).name == \"one.txt\"\n\n\ndef test_read_size_keeps_no_unread_imports() -> None:\n \"\"\"Lock the import lines this rule removed from the module and the function they never reached.\"\"\"\n import inspect\n\n from src import legacy\n source = inspect.getsource(legacy)\n import_lines = [line.strip() for line in source.splitlines() if line.strip().startswith(('import ', 'from '))]\n assert not [line for line in import_lines if 'json' in line.split()]\n assert callable(legacy.read_size)\n", "search": "def test_note_path_names_the_file() -> None:\n assert Path(note_path(\"one\")).name == \"one.txt\""}], "expect": "VERIFIED", "family": "shape", "intent_tags": ["imports", "cleanup", "dead code"], "language": "python", "min_assurance": 3, "note": "a module level function in a file whose top level import lines bind names that no other line of the file reads", "pattern_id": "drop-unused-imports", "rule": "drop-unused-imports", "targets": ["src/legacy.py::read_size"]}
{"case_id": "pat-drop-unused-imports-negative", "edits": [], "expect": "REFUSED", "family": "shape", "intent_tags": ["imports", "cleanup", "dead code"], "language": "python", "min_assurance": 3, "note": "a module level function in a file whose top level import lines bind names that no other line of the file reads", "pattern_id": "drop-unused-imports", "reason_code": "NO_UNUSED_IMPORT", "rule": "drop-unused-imports", "targets": ["src/tokens.py::count_words"]}
{"case_id": "pat-empty-len-to-truthiness-positive", "edits": [{"file": "src/baskets.py", "label": "truthiness emptiness test of 'describe'", "replace": "def describe(items):\n if not items:\n return \"empty\"\n return \"full\"", "search": "def describe(items):\n if len(items) == 0:\n return \"empty\"\n return \"full\""}, {"file": "tests/test_baskets.py", "label": "lock test 'test_describe_asks_for_truthiness' appended after 'test_first_or_none_gives_the_head_or_nothing'", "replace": "def test_first_or_none_gives_the_head_or_nothing() -> None:\n assert first_or_none([7]) == 7\n assert first_or_none([]) is None\n\n\ndef test_describe_asks_for_truthiness() -> None:\n \"\"\"Lock the truthiness test that replaced the counted emptiness.\"\"\"\n import inspect\n\n from src import baskets\n source = inspect.getsource(baskets.describe)\n assert 'not items' in source\n assert 'len(items) == 0' not in source\n", "search": "def test_first_or_none_gives_the_head_or_nothing() -> None:\n assert first_or_none([7]) == 7\n assert first_or_none([]) is None"}], "expect": "VERIFIED", "family": "shape", "intent_tags": ["collections", "truthiness", "emptiness"], "language": "python", "min_assurance": 3, "note": "a module level function that counts a value with len and compares the count to zero", "pattern_id": "empty-len-to-truthiness", "rule": "empty-len-to-truthiness", "targets": ["src/baskets.py::describe"]}
{"case_id": "pat-empty-len-to-truthiness-negative", "edits": [], "expect": "REFUSED", "family": "shape", "intent_tags": ["collections", "truthiness", "emptiness"], "language": "python", "min_assurance": 3, "note": "a module level function that counts a value with len and compares the count to zero", "pattern_id": "empty-len-to-truthiness", "reason_code": "NO_EMPTY_LEN_CHECK", "rule": "empty-len-to-truthiness", "targets": ["src/baskets.py::first_or_none"]}
{"case_id": "pat-empty-len-to-truthiness-coroutine-positive", "edits": [{"file": "src/asyncops.py", "label": "truthiness emptiness test of 'word_total'", "replace": "async def word_total(items):\n if not items:\n return 0\n return sum(len(item.split()) for item in items)", "search": "async def word_total(items):\n if len(items) == 0:\n return 0\n return sum(len(item.split()) for item in items)"}, {"file": "tests/test_asyncops.py", "label": "lock test 'test_word_total_asks_for_truthiness' appended after 'test_item_count_counts_items'", "replace": "def test_item_count_counts_items() -> None:\n assert asyncio.run(item_count([1, 2])) == 2\n\n\ndef test_word_total_asks_for_truthiness() -> None:\n \"\"\"Lock the truthiness test that replaced the counted emptiness.\"\"\"\n import inspect\n\n from src import asyncops\n source = inspect.getsource(asyncops.word_total)\n assert 'not items' in source\n assert 'len(items) == 0' not in source\n", "search": "def test_item_count_counts_items() -> None:\n assert asyncio.run(item_count([1, 2])) == 2"}], "expect": "VERIFIED", "family": "shape", "intent_tags": ["collections", "truthiness", "emptiness"], "language": "python", "min_assurance": 3, "note": "a module level function that counts a value with len and compares the count to zero", "pattern_id": "empty-len-to-truthiness", "rule": "empty-len-to-truthiness", "targets": ["src/asyncops.py::word_total"]}
{"case_id": "pat-empty-len-to-truthiness-coroutine-negative", "edits": [], "expect": "REFUSED", "family": "shape", "intent_tags": ["collections", "truthiness", "emptiness"], "language": "python", "min_assurance": 3, "note": "a module level function that counts a value with len and compares the count to zero", "pattern_id": "empty-len-to-truthiness", "reason_code": "NO_EMPTY_LEN_CHECK", "rule": "empty-len-to-truthiness", "targets": ["src/asyncops.py::item_count"]}
{"case_id": "pat-init-missing-super-positive", "edits": [{"file": "src/widgets.py", "label": "constructor chain of 'Box.__init__' opened", "replace": "def __init__(self):\n super().__init__()\n self.sides = 4\n self.closed = False", "search": "def __init__(self):\n self.sides = 4\n self.closed = False"}, {"file": "tests/test_widgets.py", "label": "lock test 'test_Box_init_calls_super_first' appended after 'test_grille_keeps_its_bars'", "replace": "def test_grille_keeps_its_bars() -> None:\n assert Grille(3).bars == 3\n\n\ndef test_Box_init_calls_super_first() -> None:\n \"\"\"Lock the super call this rule put first in the constructor, and the class that still builds.\"\"\"\n import inspect\n\n from src import widgets\n source = inspect.getsource(widgets.Box.__init__)\n assert 'super().__init__()' in source\n lines = [line.strip() for line in source.splitlines() if line.strip()]\n assert lines[0].startswith('def __init__')\n assert lines[1] == 'super().__init__()'\n created = widgets.Box()\n assert isinstance(created, widgets.Box)\n", "search": "def test_grille_keeps_its_bars() -> None:\n assert Grille(3).bars == 3"}], "expect": "VERIFIED", "family": "contracts", "intent_tags": ["construction", "inheritance", "super"], "language": "python", "min_assurance": 3, "note": "a module level class whose '__init__' takes only self, names no base of its own, and does not open the constructor chain first", "pattern_id": "init-missing-super", "rule": "init-missing-super", "targets": ["src/widgets.py::Box.__init__"]}
{"case_id": "pat-init-missing-super-negative", "edits": [], "expect": "REFUSED", "family": "contracts", "intent_tags": ["construction", "inheritance", "super"], "language": "python", "min_assurance": 3, "note": "a module level class whose '__init__' takes only self, names no base of its own, and does not open the constructor chain first", "pattern_id": "init-missing-super", "reason_code": "SUPER_CALL_ALREADY_FIRST", "rule": "init-missing-super", "targets": ["src/widgets.py::Shutter.__init__"]}
{"case_id": "pat-mutable-default-to-none-positive", "edits": [{"file": "src/slugify.py", "label": "shared default of 'add_tag'", "replace": "def add_tag(name, tags=None):\n if tags is None:\n tags = []\n tags.append(name)\n return tags", "search": "def add_tag(name, tags=[]):\n tags.append(name)\n return tags"}, {"file": "tests/test_slugify.py", "label": "lock test 'test_add_tag_has_no_shared_default' appended after 'test_join_parts_uses_its_tuple_default'", "replace": "def test_join_parts_uses_its_tuple_default() -> None:\n assert join_parts() == \"root\"\n assert join_parts((\"a\", \"b\"), sep=\"/\") == \"a/b\"\n\n\ndef test_add_tag_has_no_shared_default() -> None:\n \"\"\"Lock the default this pattern unshared, the guard that replaced it, and the call that no longer shares state.\"\"\"\n import inspect\n\n from src import slugify\n signature = inspect.signature(slugify.add_tag)\n source = inspect.getsource(slugify.add_tag)\n assert signature.parameters['tags'].default is None\n assert 'if tags is None:' in source\n first = slugify.add_tag('alpha')\n second = slugify.add_tag('beta')\n assert first != second\n", "search": "def test_join_parts_uses_its_tuple_default() -> None:\n assert join_parts() == \"root\"\n assert join_parts((\"a\", \"b\"), sep=\"/\") == \"a/b\""}], "expect": "VERIFIED", "family": "mutation", "intent_tags": ["defaults", "aliasing", "mutation"], "language": "python", "min_assurance": 3, "note": "a module level function whose parameter defaults to a list, dict or set built at definition time", "pattern_id": "mutable-default-to-none", "rule": "mutable-default-to-none", "targets": ["src/slugify.py::add_tag"]}
{"case_id": "pat-mutable-default-to-none-negative", "edits": [], "expect": "REFUSED", "family": "mutation", "intent_tags": ["defaults", "aliasing", "mutation"], "language": "python", "min_assurance": 3, "note": "a module level function whose parameter defaults to a list, dict or set built at definition time", "pattern_id": "mutable-default-to-none", "reason_code": "NOT_A_MUTABLE_DEFAULT", "rule": "mutable-default-to-none", "targets": ["src/slugify.py::join_parts"]}
{"case_id": "pat-mutable-default-to-none-coroutine-positive", "edits": [{"file": "src/asyncops.py", "label": "shared default of 'gather'", "replace": "async def gather(seed, tags=None):\n if tags is None:\n tags = []\n return tags + [seed]", "search": "async def gather(seed, tags=[]):\n return tags + [seed]"}, {"file": "tests/test_asyncops.py", "label": "lock test 'test_gather_has_no_shared_default' appended after 'test_item_count_counts_items'", "replace": "def test_item_count_counts_items() -> None:\n assert asyncio.run(item_count([1, 2])) == 2\n\n\ndef test_gather_has_no_shared_default() -> None:\n \"\"\"Lock the default this pattern unshared, the guard that replaced it, and the call that no longer shares state.\"\"\"\n import inspect\n import asyncio\n\n from src import asyncops\n signature = inspect.signature(asyncops.gather)\n source = inspect.getsource(asyncops.gather)\n assert signature.parameters['tags'].default is None\n assert 'if tags is None:' in source\n first = asyncio.run(asyncops.gather('alpha'))\n second = asyncio.run(asyncops.gather('beta'))\n assert first != second\n", "search": "def test_item_count_counts_items() -> None:\n assert asyncio.run(item_count([1, 2])) == 2"}], "expect": "VERIFIED", "family": "mutation", "intent_tags": ["defaults", "aliasing", "mutation"], "language": "python", "min_assurance": 3, "note": "a module level function whose parameter defaults to a list, dict or set built at definition time", "pattern_id": "mutable-default-to-none", "rule": "mutable-default-to-none", "targets": ["src/asyncops.py::gather"]}
{"case_id": "pat-mutable-default-to-none-coroutine-negative", "edits": [], "expect": "REFUSED", "family": "mutation", "intent_tags": ["defaults", "aliasing", "mutation"], "language": "python", "min_assurance": 3, "note": "a module level function whose parameter defaults to a list, dict or set built at definition time", "pattern_id": "mutable-default-to-none", "reason_code": "NOT_A_MUTABLE_DEFAULT", "rule": "mutable-default-to-none", "targets": ["src/asyncops.py::plain"]}
{"case_id": "pat-none-comparison-to-identity-positive", "edits": [{"file": "src/labels.py", "label": "identity comparisons of 'label_for'", "replace": "def label_for(value):\n if value is None:\n return \"none\"\n if value is not None and value == \"\":\n return \"blank\"\n return \"given\"", "search": "def label_for(value):\n if value == None:\n return \"none\"\n if value != None and value == \"\":\n return \"blank\"\n return \"given\""}, {"file": "tests/test_labels.py", "label": "lock test 'test_label_for_compares_none_by_identity' appended after 'test_is_missing_answers_for_none'", "replace": "def test_is_missing_answers_for_none() -> None:\n assert is_missing(None)\n assert not is_missing(\"\")\n\n\ndef test_label_for_compares_none_by_identity() -> None:\n \"\"\"Lock the identity tests that replaced the equality against None.\"\"\"\n import inspect\n\n from src import labels\n source = inspect.getsource(labels.label_for)\n assert '== None' not in source\n assert '!= None' not in source\n assert 'value is None' in source\n assert 'value is not None' in source\n", "search": "def test_is_missing_answers_for_none() -> None:\n assert is_missing(None)\n assert not is_missing(\"\")"}], "expect": "VERIFIED", "family": "shape", "intent_tags": ["equality", "identity", "none"], "language": "python", "min_assurance": 3, "note": "a module level function that asks whether a value is None with == or !=", "pattern_id": "none-comparison-to-identity", "rule": "none-comparison-to-identity", "targets": ["src/labels.py::label_for"]}
{"case_id": "pat-none-comparison-to-identity-negative", "edits": [], "expect": "REFUSED", "family": "shape", "intent_tags": ["equality", "identity", "none"], "language": "python", "min_assurance": 3, "note": "a module level function that asks whether a value is None with == or !=", "pattern_id": "none-comparison-to-identity", "reason_code": "NO_NONE_COMPARISON", "rule": "none-comparison-to-identity", "targets": ["src/labels.py::is_missing"]}
{"case_id": "pat-none-comparison-to-identity-coroutine-positive", "edits": [{"file": "src/asyncops.py", "label": "identity comparisons of 'describe'", "replace": "async def describe(value):\n if value is None:\n return \"nothing\"\n return str(value)", "search": "async def describe(value):\n if value == None:\n return \"nothing\"\n return str(value)"}, {"file": "tests/test_asyncops.py", "label": "lock test 'test_describe_compares_none_by_identity' appended after 'test_item_count_counts_items'", "replace": "def test_item_count_counts_items() -> None:\n assert asyncio.run(item_count([1, 2])) == 2\n\n\ndef test_describe_compares_none_by_identity() -> None:\n \"\"\"Lock the identity tests that replaced the equality against None.\"\"\"\n import inspect\n\n from src import asyncops\n source = inspect.getsource(asyncops.describe)\n assert '== None' not in source\n assert '!= None' not in source\n assert 'value is None' in source\n", "search": "def test_item_count_counts_items() -> None:\n assert asyncio.run(item_count([1, 2])) == 2"}], "expect": "VERIFIED", "family": "shape", "intent_tags": ["equality", "identity", "none"], "language": "python", "min_assurance": 3, "note": "a module level function that asks whether a value is None with == or !=", "pattern_id": "none-comparison-to-identity", "rule": "none-comparison-to-identity", "targets": ["src/asyncops.py::describe"]}
{"case_id": "pat-none-comparison-to-identity-coroutine-negative", "edits": [], "expect": "REFUSED", "family": "shape", "intent_tags": ["equality", "identity", "none"], "language": "python", "min_assurance": 3, "note": "a module level function that asks whether a value is None with == or !=", "pattern_id": "none-comparison-to-identity", "reason_code": "NO_NONE_COMPARISON", "rule": "none-comparison-to-identity", "targets": ["src/asyncops.py::present"]}
{"case_id": "pat-open-to-context-manager-positive", "edits": [{"file": "src/notes.py", "label": "scoped handle of 'read_note'", "replace": "def read_note(path):\n with open(path, \"r\", encoding=\"utf-8\") as handle:\n body = handle.read()\n return body", "search": "def read_note(path):\n handle = open(path, \"r\", encoding=\"utf-8\")\n body = handle.read()\n handle.close()\n return body"}, {"file": "tests/test_notes.py", "label": "lock test 'test_read_note_scopes_its_handle' appended after 'test_read_note_of_an_empty_file'", "replace": "def test_read_note_of_an_empty_file(tmp_path) -> None:\n path = tmp_path / \"empty.txt\"\n write_note(path, \"\")\n assert read_note(path) == \"\"\n\n\ndef test_read_note_scopes_its_handle() -> None:\n \"\"\"Lock the scope the pattern gave the handle, the close it made redundant, and the read still working.\"\"\"\n import inspect\n import os\n import shutil\n import tempfile\n\n from src import notes\n source = inspect.getsource(notes.read_note)\n assert 'with open(' in source\n assert '.close()' not in source\n assert 'handle = open(' not in source\n directory = tempfile.mkdtemp()\n try:\n path = os.path.join(directory, \"lock note.txt\")\n with open(path, \"w\", encoding=\"utf-8\") as writer:\n writer.write(\"alpha\")\n assert notes.read_note(path) == 'alpha'\n finally:\n shutil.rmtree(directory, ignore_errors=True)\n", "search": "def test_read_note_of_an_empty_file(tmp_path) -> None:\n path = tmp_path / \"empty.txt\"\n write_note(path, \"\")\n assert read_note(path) == \"\""}], "expect": "VERIFIED", "family": "resources", "intent_tags": ["files", "lifetime", "resources"], "language": "python", "min_assurance": 3, "note": "a module level function that opens a file into a name and closes that name itself", "pattern_id": "open-to-context-manager", "rule": "open-to-context-manager", "targets": ["src/notes.py::read_note"]}
{"case_id": "pat-open-to-context-manager-negative", "edits": [], "expect": "REFUSED", "family": "resources", "intent_tags": ["files", "lifetime", "resources"], "language": "python", "min_assurance": 3, "note": "a module level function that opens a file into a name and closes that name itself", "pattern_id": "open-to-context-manager", "reason_code": "ALREADY_SCOPED", "rule": "open-to-context-manager", "targets": ["src/notes.py::write_note"]}
|