Skip to content

Conversation

@Jongwan93
Copy link

Summary

Fixes #32574

This PR fixes an issue where get_type_hints() incorrectly handled callable objects with custom __signature__ attributes. Previously, these objects would fail with a TypeError because typing.get_type_hints() cannot introspect arbitrary callable instances.

Problem

When a callable object defines a custom __signature__ attribute, the existing implementation would pass the callable instance itself to typing.get_type_hints().

This broke use cases where wrappers need to preserve type information from wrapped functions by setting __signature__.

Solution

Modified get_type_hints() in decorator_utils.py to:

  1. Check for __signature__ attribute first (highest priority).
  2. Extract type hints directly from the signature object instead of calling typing.get_type_hints().
  3. Properly handle parameters and return annotations from the signature.

Changes

  • Modified python_modules/dagster/dagster/_core/decorator_utils.py:
    • Updated get_type_hints() to extract annotations directly from __signature__ when present
  • Added test in python_modules/dagster/dagster_tests/definitions_tests/test_sensor_invocation.py:
    • test_sensor_invocation_resources_callable_with_custom_signature()

Testing

  • New test test_sensor_invocation_resources_callable_with_custom_signature passes
  • All existing test_sensor_invocation.py tests pass
  • Verified backward compatibility with existing callable object handling
Screenshot 2025-10-27 at 6 10 03 PM

@MiniaczQ
Copy link

lgtm

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.

Callable object custom signatures are resolved incorrectly

2 participants