-
Notifications
You must be signed in to change notification settings - Fork 303
added variance inference test with method scoped type variable #2287
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -192,3 +192,14 @@ class ShouldBeContravariant2[T](Parent_Contravariant[T]): | |
|
|
||
| c1: ShouldBeContravariant2[int] = ShouldBeContravariant2[float]() # OK | ||
| c2: ShouldBeContravariant2[float] = ShouldBeContravariant2[int]() # E | ||
|
|
||
| class ShouldBeCovariant7[T]: | ||
| def get(self) -> T: | ||
| raise NotImplementedError | ||
|
|
||
| def add[S](self: "ShouldBeCovariant7[S]", other: list[S]) -> "ShouldBeCovariant7[S]": | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure it's correct for this method not to affect variance. (Assuming the class were named So it seems to me that if the algorithm in the spec says this class should be covariant, that might be a bug in the spec text.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this argument in its current form relies on circular reasoning, because whether or not Let's remember that
The first constraint is equivalent to Let's make the example more concrete: class C[T]:
def __init__(self, vals: list[T]) -> None:
self._vals: Sequence[T] = vals
def get(self, idx: int) -> T:
return self._vals[idx]
def add[S](self: C[S], items: list[S]) -> C[S]:
return C([*self._vals, *items])Do you have a concrete example were treating |
||
| raise NotImplementedError | ||
|
|
||
|
|
||
| d1: ShouldBeCovariant7[object] = ShouldBeCovariant7[int]() # OK | ||
| d2: ShouldBeCovariant7[int] = ShouldBeCovariant7[object]() # E | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be updated to Partial if this is merged.