Fix: Resolve TypeError in value_to_type on Python 3.13 (issue #1188) #1189
      
        
          +27
        
        
          −3
        
        
          
        
      
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
What was changed
This PR fixes a TypeError in temporalio/converter.py that occurs on Python 3.13.
The isinstance(key, key_type) check in the value_to_type function was modified to include a guard: not isinstance(key_type, type). This prevents the illegal isinstance() call from being used on typing generics like typing.Literal.
A new unit test is also added to reproduce this specific bug and verify the fix.
Why?
On Python 3.13+, isinstance() can no longer be used with subscripted generics (like typing.Literal), and doing so raises a TypeError. The value_to_type function was not handling this, causing data conversion to fail for dictionaries with Literal keys.
This fix short-circuits the logic to avoid the illegal call, allowing the function to fall through to the correct value_to_type call which already handles Literal types properly.
Checklist
Closes [Bug] converter.py: TypeError on Python 3.13 when using isinstance with typing.Literal #1188
How was this tested:
A new unit test was added (test_value_to_type_literal_key_bug) that specifically reproduces this bug. This test fails before the fix and passes with it. The full test suite was also run successfully via poe test.
Any docs updates needed?
No. This is a minor internal bug fix.