Download patterns/pattern_cases.jsonl from tailot/codex-python: direct link, hf CLI and curl.
- Browser
- Download file 18.3 kB
-
https://huggingface.co/datasets/tailot/codex-python/resolve/db2c7db03ad5e9ec438a8fbb095abf531338a717/patterns/pattern_cases.jsonl
- Command line
-
hf download hf://datasets/tailot/codex-python@db2c7db03ad5e9ec438a8fbb095abf531338a717/patterns/pattern_cases.jsonl
-
curl -L -o pattern_cases.jsonl https://huggingface.co/datasets/tailot/codex-python/resolve/db2c7db03ad5e9ec438a8fbb095abf531338a717/patterns/pattern_cases.jsonl
18.3 kB
| {"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-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-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-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-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-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-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"]} | |