Fix type parameter forwarding for inherited generics#328
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #328 +/- ##
==========================================
- Coverage 99.87% 99.87% -0.01%
==========================================
Files 35 35
Lines 2347 2346 -1
==========================================
- Hits 2344 2343 -1
Misses 3 3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
|
Hi @brentyi, This seems to have broken something for me, it's a functionality I implemented replicating your import dataclasses
from typing import Annotated, Union
import tyro
@dataclasses.dataclass(kw_only=True, frozen=True)
class OptimizerConfig:
lr: float = 1e-5
weight_decay: float = 0.0
@dataclasses.dataclass(kw_only=True, frozen=True)
class AdamConfig(OptimizerConfig):
betas: tuple[float, float] = (0.9, 0.999)
eps: float = 1e-8
amsgrad: bool = False
fused: bool | None = None
@dataclasses.dataclass(kw_only=True, frozen=True)
class SGDConfig(OptimizerConfig):
momentum: float = 0
dampening: float = 0
nesterov = False
fused: bool | None = None
# works
# OptimizerConfig = Annotated[
# OptimizerConfig,
# tyro.conf.arg(constructor_factory=lambda: Union[AdamConfig, SGDConfig]), # type: ignore
# ]
# crashes
OptimizerConfig.__tyro_markers__ = ( # type: ignore
tyro.conf.arg(
constructor_factory=lambda: Union[AdamConfig, SGDConfig] # type: ignore
),
)
@dataclasses.dataclass
class Config:
optimizer: OptimizerConfig = AdamConfig()
def main(config: Config) -> None:
print(config)
if __name__ == "__main__":
config = tyro.cli(Config)
main(config)On 0.9.27 this crashes for the case where I'm setting |
brentyi
added a commit
that referenced
this pull request
Dec 1, 2025
* Fix edge case for inherited generics * ruff * More correct fix, test for deeper nesting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR fixes an edge case and adds test cases for inheritance structures that look like this:
where assignments for the
T2type parameter are applied tofield2, but not correctly forwarded tofield1.cc #327