Skip to content

Conversation

@asukaminato0721
Copy link
Contributor

fix #1176

@meta-cla meta-cla bot added the cla signed label Oct 22, 2025
@asukaminato0721 asukaminato0721 marked this pull request as ready for review October 22, 2025 10:23
@meta-codesync
Copy link

meta-codesync bot commented Oct 24, 2025

@kinto0 has imported this pull request. If you are a Meta employee, you can view this in D85445913.

def __radd__(self, other) -> Self:
return self
assert_type(A() + B(), A) # E: `A.__add__` is deprecated
assert_type(A() + B(), A | B) # E: `A.__add__` is deprecated
Copy link
Contributor

Choose a reason for hiding this comment

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

does this A | B imply we choose A | B in this example?

is it worth adding a test for that, and should it be just A?

Copy link
Contributor

@kinto0 kinto0 Oct 24, 2025

Choose a reason for hiding this comment

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

The current behavior for these reflected operators is:

  • Try the "forward" operator, if that works, use the return type from that
  • If the forward operator fails, try the reflected operator, using it's return type if it succeeds
  • If both the forward and reflected operators fail, error and use the return type from the forward operator

is this level of strictness practical? might be worth a discussion

Copy link
Contributor

@kinto0 kinto0 left a comment

Choose a reason for hiding this comment

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

thanks for the contribution! we tested this change against instagram and it introduced a lot of unrelated type errors. not entirely sure we want to merge it just yet. it might be worth discussing it more at an office hours or on discord if you're still interested in this issue

];
self.try_binop_calls(&calls_to_try, range, errors, &context)
let class_type_of = |ty: &Type| -> Option<ClassType> {
match ty {
Copy link
Contributor

Choose a reason for hiding this comment

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

mapping over type like this is almost never what we want: it's hard to maintain and prone to errors

def __radd__(self, other) -> Self:
return self
assert_type(A() + B(), A) # E: `A.__add__` is deprecated
assert_type(A() + B(), A | B) # E: `A.__add__` is deprecated
Copy link
Contributor

@kinto0 kinto0 Oct 24, 2025

Choose a reason for hiding this comment

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

The current behavior for these reflected operators is:

  • Try the "forward" operator, if that works, use the return type from that
  • If the forward operator fails, try the reflected operator, using it's return type if it succeeds
  • If both the forward and reflected operators fail, error and use the return type from the forward operator

is this level of strictness practical? might be worth a discussion

@asukaminato0721 asukaminato0721 marked this pull request as draft October 25, 2025 09:44
Copy link
Contributor

@yangdanny97 yangdanny97 left a comment

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

report unsafe operator type on subclasses

4 participants