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

Fix inference for properties with __call__ #15926

Merged
merged 5 commits into from
Aug 30, 2023

Conversation

hauntsaninja
Copy link
Collaborator

Fixes #5858

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@hauntsaninja hauntsaninja marked this pull request as ready for review August 23, 2023 07:41
@github-actions

This comment has been minimized.

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.

LG, but I have some suggestions

result = expanded_signature.ret_type
else:
result = expanded_signature
if var.is_initialized_in_class and (not is_instance_var(var) or mx.is_operator):
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to avoid extra nesting level by computing something before the first if? If yes, I would prefer that. This function is already hard to read.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done!

class A:
@property
@decorator
def f(self) -> int: ...
Copy link
Member

Choose a reason for hiding this comment

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

People recently complained (don't remember where) that this use case:

def make_method() -> SomeCallbackProtocol: ...
class A:
    meth = make_method()

is not handled the same way as

def make_method_callable() -> Callable[[int], int]: ...
class B:
    meth = make_method_callable()

(because certain special-casing only applies to callable types). I am 95% sure this PR should fix that as well (or maybe with very few modifications), if yes, could you please add such test as well?

Copy link
Collaborator Author

@hauntsaninja hauntsaninja Aug 30, 2023

Choose a reason for hiding this comment

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

Thanks for mentioning this! It's not fixed by this change, but should be doable fix. I will make a follow up PR

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

twine (https://github.com/pypa/twine)
+ twine/settings.py:131: error: Redundant cast to "str | None"  [redundant-cast]
+ twine/settings.py:137: error: Redundant cast to "str | None"  [redundant-cast]

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.

lru_cache annotation doesn't work as a property
2 participants