Skip to content

use base type as hint when inferring #12284

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

Closed
wants to merge 4 commits into from
Closed

Conversation

Riolku
Copy link

@Riolku Riolku commented Mar 3, 2022

Would help with #12268. Modified a test because the two behaviours conflict right now.

Would help with python#12268. Modified a test because the two behaviours 
conflict right now.
@github-actions

This comment has been minimized.

@Riolku
Copy link
Author

Riolku commented Mar 4, 2022

To motivate this PR, consider the following code (which is also a test case):

from typing import Union, List

class A: pass
class B: pass

U = Union[A, B]

class Base:
    variable1 : List[U] = []
    variable2 : List[U] = []

class Derived(Base):
    variable1 = [A()]
    variable2 = variable1

before this PR, although variable1 is type-checked against List[U], it is inferred as List[A], which makes the last line an error. This PR instead uses the base type as a hint for the inference, if possible.

@Riolku
Copy link
Author

Riolku commented Mar 4, 2022

Note that this hinting is already done, in order to infer [A()] as List[U], so that that line doesn't throw.

@Riolku
Copy link
Author

Riolku commented Mar 4, 2022

Since the issue is open, I think it's fair to say that this would fix #12268

@Riolku
Copy link
Author

Riolku commented Mar 4, 2022

Sorry for a bit of spam, normally I'd force push, I can't force github to link the issue, for some reason.

@Riolku
Copy link
Author

Riolku commented Mar 4, 2022

I give up. Maybe a maintainer can help.

@github-actions

This comment has been minimized.

1 similar comment
@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2022

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@Riolku
Copy link
Author

Riolku commented Mar 18, 2022

Hey, I think this PR is ready for someone to look over. It's been around two weeks, and I don't want it to get lost in the sea of PRs. Does anyone mind taking a look?

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! I believe this was fixed in #13494

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.

2 participants