Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial support for type parameters in class methods #238

Merged
merged 6 commits into from
Jan 17, 2025

Conversation

brentyi
Copy link
Owner

@brentyi brentyi commented Jan 17, 2025

The goal of this PR is to resolve type parameters in class methods like this:

import tyro

class Base[T]:
    @classmethod
    def f(cls, x: T) -> T:
        print(x)
        return x

class Subclass(Base[int]):
    pass

tyro.cli(Subclass.f)  # Should have argument `--x INT`

tyro.cli(Base[int].f) will still not work, because we can't distinguish between Base[int].f and Base.f at runtime. The "What's not supported" doc has been updated to explain this: https://brentyi.github.io/tyro/whats_supported/#what-s-not-supported

@brentyi brentyi changed the title Support type parameters in class methods Partial support for type parameters in class methods Jan 17, 2025
Copy link

codecov bot commented Jan 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.78%. Comparing base (b5d8bc7) to head (834d051).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #238      +/-   ##
==========================================
- Coverage   99.78%   99.78%   -0.01%     
==========================================
  Files          28       28              
  Lines        2329     2326       -3     
==========================================
- Hits         2324     2321       -3     
  Misses          5        5              
Flag Coverage Δ
unittests 99.78% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@brentyi brentyi force-pushed the brent/classmethod_type_params branch from aa22bd1 to 834d051 Compare January 17, 2025 06:52
@brentyi brentyi merged commit 87ca73f into main Jan 17, 2025
17 checks passed
@brentyi brentyi deleted the brent/classmethod_type_params branch January 17, 2025 07:14
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.

1 participant