Skip to content

chore(build): fix all mypy errors in setup.py#17963

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits into
mainfrom
vlad/fix-setup-py-mypy-errors
May 19, 2026
Merged

chore(build): fix all mypy errors in setup.py#17963
gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits into
mainfrom
vlad/fix-setup-py-mypy-errors

Conversation

@vlad-scherbich

@vlad-scherbich vlad-scherbich commented May 7, 2026

Copy link
Copy Markdown
Contributor

Description

Fix a few lint errors in setup.py. Discovered when working on #17959.

Changes

  • Add proper type annotations to LibraryDownload class attributes (name, version, url_root, available_releases, translate_suffix), resolving var-annotated and assignment errors in subclasses.
  • Suppress cmake.CMAKE_BIN_DIR attr-defined errors (runtime-only attribute not declared in the cmake package stubs).
  • Suppress method-assign errors for intentional debug-instrumentation monkey-patching of CustomBuildExt methods.
  • Wrap src.suffix in bool() to fix return type mismatch in CMakeExtension.get_sources.

Testing

  • commit passed pre-commit hooks
  • CI

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented May 7, 2026

Copy link
Copy Markdown

Codeowners resolved as

mypy.ini                                                                @DataDog/python-guild @DataDog/apm-core-python
setup.py                                                                @DataDog/python-guild

@pr-commenter

pr-commenter Bot commented May 7, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-05-18 20:33:12

Comparing candidate commit 0182cf8 in PR branch vlad/fix-setup-py-mypy-errors with baseline commit 66bfade in branch main.

Found 0 performance improvements and 5 performance regressions! Performance is the same for 592 metrics, 10 unstable metrics.

scenario:iastaspects-lstrip_aspect

  • 🟥 execution_time [+63.299µs; +67.846µs] or [+23.829%; +25.541%]

scenario:iastaspects-translate_aspect

  • 🟥 execution_time [+36.862µs; +43.951µs] or [+7.561%; +9.016%]

scenario:iastaspectsospath-ospathbasename_aspect

  • 🟥 execution_time [+102.559µs; +109.723µs] or [+24.320%; +26.019%]

scenario:span-start

  • 🟥 execution_time [+1.318ms; +1.463ms] or [+8.472%; +9.402%]

scenario:telemetryaddmetric-1-count-metric-1-times

  • 🟥 execution_time [+278.678ns; +303.417ns] or [+13.502%; +14.701%]

@vlad-scherbich vlad-scherbich added the changelog/no-changelog A changelog entry is not required for this PR. label May 7, 2026
@vlad-scherbich vlad-scherbich marked this pull request as ready for review May 7, 2026 19:27
@vlad-scherbich vlad-scherbich requested a review from a team as a code owner May 7, 2026 19:27
Comment thread setup.py
Enable check_untyped_defs for setup.py in mypy.ini to catch errors
inside untyped function bodies (fixes Kowalski unused-ignore feedback).

- expected_checksums: dict[str, str] -> dict[str, dict[str, str]]
- tarfile.open: pass streaming mode as keyword arg (mode=r|gz)
- source_files: list[Path] annotation, newest_source_time: float (x2)
- Add missing type: ignore[attr-defined] on cmake.CMAKE_BIN_DIR in build_libdd_wrapper
- built: set[str] annotation in _get_common_cmake_args
- Fix ext.name -> ext in DebugMetadata.write_report (keys are str)
main now enables strict mode globally. Relax annotation-only checks
in [mypy-setup] (same treatment as [mypy-conf] for docs) while keeping
check_untyped_defs=true to preserve the error coverage from the prior commit.

Also fix real errors now surfaced:
- Remove unreachable else branch in retry decorator (all except types handled)
- Import CythonExtension directly from Cython.Distutils.extension to
  avoid no_implicit_reexport attr-defined errors; drop now-unused
  import Cython.Distutils
@vlad-scherbich vlad-scherbich force-pushed the vlad/fix-setup-py-mypy-errors branch from e6b1683 to fd1eb8f Compare May 18, 2026 19:52
@vlad-scherbich vlad-scherbich requested a review from a team as a code owner May 18, 2026 19:52
Add return-type and parameter annotations to all setuptools command
overrides (the public API that distutils/setuptools calls into):

- PatchedDistribution.__init__(attrs)
- ExtensionHashes.run()
- CustomBuildRust.initialize_options(), run()
- LibraryDownload.run() (classmethod)
- LibraryDownloader.run()
- CleanLibraries.remove_*() staticmethods, run()
- CustomBuildExt.run(), build_extensions(), build_extension(ext)
- CMakeExtension.__init__(...) — also corrects dependencies: list[Path]
  (was undocumented; build_extension_cmake uses .parent/.glob on them)

Private helper methods remain unannotated; [mypy-setup] still relaxes
disallow_untyped_defs/calls for those.
@gh-worker-dd-mergequeue-cf854d gh-worker-dd-mergequeue-cf854d Bot merged commit a6282d1 into main May 19, 2026
1175 checks passed
@gh-worker-dd-mergequeue-cf854d gh-worker-dd-mergequeue-cf854d Bot deleted the vlad/fix-setup-py-mypy-errors branch May 19, 2026 14:21
vlad-scherbich added a commit that referenced this pull request May 20, 2026
## Description

Fix a few lint errors in setup.py. Discovered when working on #17959.

## Changes
- Add proper type annotations to LibraryDownload class attributes (name, version, url_root, available_releases, translate_suffix), resolving var-annotated and assignment errors in subclasses.
- Suppress cmake.CMAKE_BIN_DIR attr-defined errors (runtime-only attribute not declared in the cmake package stubs).
- Suppress method-assign errors for intentional debug-instrumentation monkey-patching of CustomBuildExt methods.
- Wrap src.suffix in bool() to fix return type mismatch in CMakeExtension.get_sources.

## Testing

* commit passed pre-commit hooks
* CI


Co-authored-by: vlad.scherbich <vlad.scherbich@datadoghq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/no-changelog A changelog entry is not required for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants