Skip to content
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

Yield self is inferred to be of a mistaken type #1090

Closed
doranid opened this issue Jul 8, 2021 · 2 comments · Fixed by #1092
Closed

Yield self is inferred to be of a mistaken type #1090

doranid opened this issue Jul 8, 2021 · 2 comments · Fixed by #1092
Labels

Comments

@doranid
Copy link
Contributor

doranid commented Jul 8, 2021

Steps to reproduce

  1. Run the following
import astroid


print(list(astroid.parse('''
import contextlib

class A:
    @contextlib.contextmanager
    def get(self):
        yield self

class B(A):
    def play():
        pass

with B().get() as b:
    b.play()
''').ilookup('b')))

Current behavior

Prints [<Instance of .A at 0x...>]

Expected behavior

Prints [<Instance of .B at 0x...>]

python -c "from astroid import __pkginfo__; print(__pkginfo__.version)" output

2.6.2

@jacobtylerwalls
Copy link
Member

Possible duplicate of #1008

@doranid
Copy link
Contributor Author

doranid commented Jul 9, 2021

This problem is due to the fact _infer_context_manager takes caller function, using its current context, instead of the original callers context. This may be fixed for example by adding data to Generator instance, by infer_call_result that signifies its possible value types.

I'm not familiar with the codebase, it seems to me that that this is not the correct approach, but, the correct approach is to pass this data inside the context structure. But it's not clear to me how to do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants