← open_datasets
ast codemod transformationpython · communitycommunity · karma-rewarded● active

Python Codemod Transformation with Dual Validation

sponsor: Platform
connect to contribute →

Each item is a python codemod transformation with dual validation example providing Task description, Transformation type, Transformation parameters (curator-authored ground truth, JSON), Original code (Python), Transformed code (Python) -- THE GRADED ARTIFACT, Behavior check test cases (curator-authored ground truth, JSON). Favour realistic, self-contained cases; avoid duplicating public benchmark examples or trivial ones.

karma / item
40 karma
capacity reserved / target
60 / 5,000
final accepted
60
contributors
1
license
CC-BY-4.0
Karma per final accepted item

Secured after final acceptance. It is added to your balance when this pool publishes after its shared review window closes cleanly. Rejected items do not qualify.

secured on acceptance40 karma
Community terms

Platform-authored spec, open on delivery.

publishes tohugging face
licenseCC-BY-4.0
Quality signals

Measured pipeline stats for this dataset. A dash means the platform does not publish that measure for this pool.

submitted items60
rejected items0
duplicate rate1%
contributors1
validators1

// dataset_type_samples

Illustrative samples authored for the AST Codemod Transformation dataset type.

original_code
import logging

logger = logging.getLogger(__name__)


def read_config_value(path, default):
    try:
        with open(path) as f:
            return f.read().strip()
    except Exception:
        pass
    return default


def load_settings(paths_and_defaults):
    results = []
    for path, default in paths_and_defaults:
        results.append(read_config_value(path, default))
    return results
behavior_check
[
  {
    "args": [
      [
        [
          "/no/such/path/act-sample-a.cfg",
          "fallback_a"
        ]
      ]
    ],
    "expected_output": [
      "fallback_a"
    ],
    "expect_log_call": true
  },
  {
    "args": [
      [
        [
          "/no/such/path/act-sample-b.cfg",
          42
        ],
        [
          "/no/such/path/act-sample-c.cfg",
          7
        ]
      ]
    ],
    "expected_output": [
      42,
      7
    ],
    "expect_log_call": true
  },
  {
    "args": [
      []
    ],
    "expected_output": []
  },
  {
    "args": [
      [
        [
          "/no/such/path/act-sample-d.cfg",
          null
        ]
      ]
    ],
    "expected_output": [
      null
    ],
    "expect_log_call": true
  }
]
task_description
In a settings-file loader that silently swallows read failures, replace the bare except Exception: pass with a real logging call while still falling back to the caller-supplied default.
transformed_code
import logging

logger = logging.getLogger(__name__)


def read_config_value(path, default):
    try:
        with open(path) as f:
            return f.read().strip()
    except Exception:
        logger.exception("failed to read config file %s", path)
    return default


def load_settings(paths_and_defaults):
    results = []
    for path, default in paths_and_defaults:
        results.append(read_config_value(path, default))
    return results
transformation_typeexcept_pass_to_logging
transformation_params
{
  "entry_point_original": "load_settings",
  "entry_point_transformed": "load_settings",
  "min_conversions": 1
}

// sample_item

Approved public samples for this AST Codemod Transformation dataset. These are source artifacts attached to this program, not generated examples.

No public sample item is available for this dataset yet.
Ready to contribute to this dataset?
Contribute to this open pool. 40 karma is secured on each final acceptance and added to your balance after verified publication.
connect to contribute →