Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

closes #19752

This PR adds optional explicit typing for the Variable.get and Variable.aget methods, allowing users to declare the expected type when retrieving a variable:

var = Variable[str].get("my_variable")

Implementation

  • Makes Variable class generic with TypeVar T bounded to StrictVariableValue
  • Uses TypeVar with default=StrictVariableValue from typing_extensions for backward compatibility (unparameterized Variable.get() still works as before)
  • Adds overloads for get/aget to properly type the return value:
    • Without default: returns T | None
    • With default: returns T
  • Both sync (get) and async (aget) methods support the same typing behavior

Human Review Checklist

  • Verify the overload signatures correctly capture the intended typing behavior
  • Confirm backward compatibility - existing code using Variable.get() without type parameter should continue to work
  • The return type annotation changed from StrictVariableValue to StrictVariableValue | None which is more accurate - verify this doesn't cause issues elsewhere

Checklist

  • This pull request references any related issue by including "closes <link to issue>"
  • If this pull request adds new functionality, it includes unit tests that cover the changes
  • If this pull request removes docs files, it includes redirect settings in mint.json.
  • If this pull request adds functions or classes, it includes helpful docstrings.

Link to Devin run: https://app.devin.ai/sessions/d315656d34b445ee9e1d1ca820411d24
Requested by: Nate Nowack ([email protected]) (@zzstoatzz)

This adds optional explicit typing for the Variable.get and Variable.aget methods,
allowing users to declare the expected type when retrieving a variable:

    var = Variable[str].get('my_variable')

The implementation:
- Makes Variable class generic with TypeVar T bounded to StrictVariableValue
- Uses TypeVar default for backward compatibility (unparameterized Variable still works)
- Adds overloads for get/aget to properly type the return value based on whether
  a default is provided
- Both sync (get) and async (aget) methods support the same typing behavior

Closes #19752

Co-Authored-By: Nate Nowack <[email protected]>
@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@github-actions github-actions bot added the enhancement An improvement of an existing feature label Dec 12, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 12, 2025

CodSpeed Performance Report

Merging #19764 will not alter performance

Comparing devin/1765568895-variable-generic-typing (a95c98a) with main (57d6b87)

Summary

✅ 2 untouched

@zzstoatzz zzstoatzz marked this pull request as ready for review December 12, 2025 22:17
Copy link
Collaborator

@zzstoatzz zzstoatzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checked it out locally and LGTM, but want a sanity check from @desertaxle !

Copy link
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@zzstoatzz zzstoatzz merged commit af1a9c9 into main Dec 13, 2025
61 checks passed
@zzstoatzz zzstoatzz deleted the devin/1765568895-variable-generic-typing branch December 13, 2025 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement An improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide optional explicit typing for Variable.get method

3 participants