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

Rebind self-types in subclass methods without Self annotation #15541

Merged
merged 3 commits into from
Jun 29, 2023

Conversation

ilevkivskyi
Copy link
Member

Fixes #15529

The fix is straightforward, hopefully there will be no fallout. (Note that #14075 would also fix this, but I am still not sure we should do that)

@github-actions

This comment has been minimized.

@AlexWaygood
Copy link
Member

The mypyc TypedDict test failures are due to the latest typing_extensions release, not this PR: #15542

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@ilevkivskyi
Copy link
Member Author

This is quite minor, so I am going to merge this later today or tomorrow unless there are comments/objections.

@ilevkivskyi ilevkivskyi merged commit b995e16 into python:master Jun 29, 2023
20 checks passed
@ilevkivskyi ilevkivskyi deleted the fix-self-subclass branch June 29, 2023 22:34
@cdce8p
Copy link
Collaborator

cdce8p commented Jul 3, 2023

This seems to cause a regression with dataclasses. In particular None types are striped from Callable types (both arguments and return types) even with --strict-optional set.

from dataclasses import dataclass
from typing import Callable, assert_type

@dataclass
class Description:
    name_fn: Callable[[int | None], str | None]


def f(d: Description) -> None:
    assert_type(d.name_fn, Callable[[int | None], str | None])  # E: \
        # Expression is of type "Callable[[int], str]", not "Callable[[int | None], str | None]"
mypy --strict-optional test.py

@ilevkivskyi
Copy link
Member Author

Yeah, this is annoying, let me do something to prevent this kind of things once and for all.

@ilevkivskyi
Copy link
Member Author

@cdce8p See #15571

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.

mypy doesn't correctly infer Self attributes on subclasses
4 participants