Skip to content

fix(core): remove four dead duplicate definitions shadowed by a later copy - #6267

Open
Anai-Guo wants to merge 1 commit into
aws:masterfrom
Anai-Guo:fix-core-remove-shadowed-duplicate-definitions
Open

fix(core): remove four dead duplicate definitions shadowed by a later copy#6267
Anai-Guo wants to merge 1 commit into
aws:masterfrom
Anai-Guo:fix-core-remove-shadowed-duplicate-definitions

Conversation

@Anai-Guo

Copy link
Copy Markdown

Issue

None (found by auditing duplicate definitions at the same scope).

Description

Four names in the shipped source are bound twice at the same scope. Python simply rebinds the name, so the first definition is unreachable dead code:

file name the dead copy
sagemaker-core/.../utils/utils.py snake_to_pascal predates SPECIAL_SNAKE_TO_PASCAL_MAPPINGS and does not consult it
sagemaker-core/.../training/configs.py OutputDataConfig identical fields, only the docstring differs
sagemaker-core/.../remote_function/job.py _get_initial_job_state byte-for-byte identical
sagemaker-serve/.../model_builder_utils.py _ModelBuilderUtils._extract_speculative_draft_model_provider byte-for-byte identical (same class body)

The snake_to_pascal pair is the interesting one: the dead first copy would mis-convert names covered by the special-case mapping (e.g. volume_size_in_g_bVolumeSizeInGb instead of VolumeSizeInGB). It never runs — every caller resolves the second, mapping-aware definition — but leaving it there invites someone to "fix" the wrong one.

In every case this PR deletes the dead copy and keeps the one that was already live, so it is a no-op at runtime (+0 / −71).

Testing done

  • AST proof: for each file, compared ast.dump of the final binding of every module-level and class-level name before and after the edit — identical in all four files.
  • Confirmed no module-level code references any of these names between the two definitions (which would otherwise bind the earlier object at import time).
  • Runtime smoke check:
    • snake_to_pascal("volume_size_in_g_b") == "VolumeSizeInGB" ✅ (special mapping still honoured)
    • snake_to_pascal("output_data_config") == "OutputDataConfig"
    • OutputDataConfig.model_fields == {s3_output_path, kms_key_id, compression_type}
  • pytest sagemaker-core/tests/unit/utils — 25 passed, unchanged.

Merge Checklist

  • I have read the CONTRIBUTING doc
  • I certify that the changes I am introducing will be backward compatible, and I have discussed concerns about this, if any, with the Python SDK team
  • I used the commit message format described in CONTRIBUTING
  • I have passed the region in to all S3 and STS clients that I've initialized as part of this change.
  • I have updated any necessary documentation, including READMEs and API docs (if appropriate)

Tests

  • I have added tests that prove my fix is effective or that my feature works (no behaviour change; existing tests cover the surviving definitions)
  • I have checked that my tests are not configured for a specific region or account

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

🤖 Generated with Claude Code

… copy

Each of these names is bound twice at the same scope, so the first definition is
unreachable - Python simply rebinds the name and the earlier object is
discarded:

* `sagemaker/core/utils/utils.py` - `snake_to_pascal` is defined twice. The
  first copy predates `SPECIAL_SNAKE_TO_PASCAL_MAPPINGS` and does not consult
  it, so it would mis-convert e.g. `volume_size_in_g_b`. It never runs: the
  second definition (which does consult the mapping) is the one every caller
  gets.
* `sagemaker/core/training/configs.py` - `OutputDataConfig` is declared twice
  with identical fields; only the docstrings differ. The later, more accurate
  docstring is the one that survives.
* `sagemaker/core/remote_function/job.py` - `_get_initial_job_state` is defined
  twice, byte for byte.
* `sagemaker/serve/model_builder_utils.py` -
  `_ModelBuilderUtils._extract_speculative_draft_model_provider` is defined
  twice in the same class body, byte for byte.

In every case this removes the dead copy and keeps the one that was already
live, so the change is a no-op at runtime.

Verified by comparing `ast.dump` of the final binding for every module-level and
class-level name before and after: identical in all four files. Also confirmed
no module-level code references any of these names between the two definitions
(which would otherwise bind the earlier object at import time).

Smoke-checked at runtime:
`snake_to_pascal("volume_size_in_g_b") == "VolumeSizeInGB"` and
`OutputDataConfig.model_fields == {s3_output_path, kms_key_id, compression_type}`,
and `pytest sagemaker-core/tests/unit/utils` stays at 25 passed.

Signed-off-by: Anai-Guo <antai12232931@outlook.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant