Skip to content

Fix crash related with __getattr__ and __call__ #7446

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

Merged

Conversation

onlined
Copy link
Contributor

@onlined onlined commented Sep 2, 2019

Fixes #7243.

Copy link
Member

@ilevkivskyi ilevkivskyi 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 PR! I think this may be not the best to way to fix this however. An ideal fix would be to actually implement #3832. But this may be a too big task, so I think it would also make sense to essentially copy the logic from your previous PR #6655 to find_member().

Also, could you please add some tests?

@onlined
Copy link
Contributor Author

onlined commented Sep 3, 2019

Thanks for the review! I changed the logic as you proposed. I will add tests, but I couldn't think of some simple snippet which can call find_member with __call__. Could you give a suggestion?

@ilevkivskyi
Copy link
Member

I think the simplest way to trigger the crash is:

from typing import Callable, Any

class C:
    def __getattr__(self, attr: str) -> C: ...

def do(cd: Callable[..., Any]) -> None:
    ...

do(C())

Using this I think you get the idea how to trigger similar crashes in constraints.py, join.py, etc. There is no need to add a test for every call site, just couple test cases will be enough.

@onlined
Copy link
Contributor Author

onlined commented Sep 15, 2019

Added.

Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

👍 Nice!

@ilevkivskyi ilevkivskyi merged commit 125ef0d into python:master Sep 15, 2019
nanshu added a commit to nanshu/mypy that referenced this pull request Aug 14, 2020
nanshu added a commit to nanshu/mypy that referenced this pull request Aug 14, 2020
1. limit the version of the test deps in test-requirements.txt by release data (i.e. Jan 16 2019, when v0.660 was released)
2. ./runtests.py and all tests pass
3. add tests from python#6655 and python#7446 and ./runtests.py and new test cases fail
4. apply changes from python#6655 and python#7446 manually
5. run tests and all pass
@onlined onlined deleted the fix/call-getattr-callable-recursion branch February 11, 2024 21:19
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.

__getattr__ returning self type results in RecursionError in overloaded contexts
2 participants