You can use `types.FunctionType` instead of `builtins.function`. See the original crash in the CI results here python/typeshed#876.