I just ran migrate-call-by-name on a WIP backend. ...
# development
p
I just ran migrate-call-by-name on a WIP backend. Then mypy complained about one of my rules returning
Any
, even though it has a return type hint.
Copy code
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:
Copy code
@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:
Copy code
@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:
Copy code
@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
?
1
Oh. I guess mypy might be having issues going through
@rule(...)
to infer a type hint. https://github.com/python/typing/discussions/1284