proud-dentist-22844
07/27/2024, 3:56 AMAny, even though it has a return type hint.
23:01:20.36 [ERROR] Completed: Typecheck using MyPy - mypy - mypy failed (exit code 1).
src/python/pants/backend/nfpm/rules.py: note: In function "package_nfpm_rpm_package":
src/python/pants/backend/nfpm/rules.py:160:5: error: Returning Any from function declared to return "BuiltPackage" [no-any-return]
return await package_nfpm_package(NfpmPackageRequest(field_set), **implicitly())
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Found 1 error in 1 file (checked 1 source file)
So, I had to change from this:
@rule
async def package_nfpm_rpm_package(field_set: NfpmRpmPackageFieldSet) -> BuiltPackage:
return await package_nfpm_package(NfpmPackageRequest(field_set), **implicitly())
to this, with an explicit type hint:
@rule
async def package_nfpm_rpm_package(field_set: NfpmRpmPackageFieldSet) -> BuiltPackage:
built_package: BuiltPackage = await package_nfpm_package(
NfpmPackageRequest(field_set), **implicitly()
)
return built_package
where the package_nfpm_package rule is type hinted:
@rule(level=LogLevel.INFO)
async def package_nfpm_package(
request: NfpmPackageRequest,
nfpm_subsystem: NfpmSubsystem,
platform: Platform,
) -> BuiltPackage:
Any idea why mypy couldn't tell that package_nfpm_package returns BuiltPackage?proud-dentist-22844
07/27/2024, 4:22 AM@rule(...) to infer a type hint.
https://github.com/python/typing/discussions/1284