-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Draft: Solve intermediate variable bug #19399
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: master
Are you sure you want to change the base?
Draft: Solve intermediate variable bug #19399
Conversation
or ( # HACK to fix testLiteralAndGenericWithUnion | ||
isinstance(outer_ret_type, UnionType) | ||
and any(is_subtype(val, joint_ret_type) for val in outer_ret_type.items) | ||
) |
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.
Without this hack, testLiteralAndGenericWithUnion
fails (see footnote 1 in OP). Not sure if this is the appropriate way to do it
lambda i: self.accept(args[i]), | ||
) | ||
|
||
# ??? QUESTION: Do we need to recompute arg_types and pass1_args here??? |
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.
It seems to work both with/without recomputing arg_types
here, but I am not sure.
Attempted fix for #19304. Looking for feedback, as this was mostly a trial-and-error process.
self.infer_function_type_arguments_using_context
. Instead, we now use a functioninfer_constraints_from_context
that only yields the constraints.infer_function_type_arguments
to now include the context.We compute 2 sets of constraints: the "outer constraints", determined by the context, and the "inner constraints" determined by the callable type. From this, we compute 2 solutions:
Modified tests
testBinaryOperatorContext
(see Assigning to intermediate variable changes type checking results #19304)testRecursiveAliasWithRecursiveInstance
.2Footnotes
This was needed to fix
testLiteralAndGenericWithUnion
, because the outer solution wasint | Literal["foo"]
whereas the joint solution wasLiteral["foo"]?
which got converted intostr
later. ↩previously,
a=b
followed bya=[[b]]
madea
be inferred as__main__.B
followed bybuiltins.list[Union[__main__.A, typing.Sequence[Union[__main__.A, ...]]]]
. Now, it gets more precisely inferred asbuiltins.list[builtins.list[__main__.B]]
. And afterwards,join(a,b)
get more precisely inferred astyping.Sequence[typing.Sequence[__main__.B]]
rather thantyping.Sequence[Union[__main__.A, typing.Sequence[Union[__main__.A, ...]]]]
previously. See: https://mypy-play.net/?mypy=latest&python=3.12&gist=619a7fa6c3ec9d75bd1492bf8e68432c ↩