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

Phantom types for mutable base types #128

Closed
sobolevn opened this issue Jul 14, 2021 · 1 comment · Fixed by #154
Closed

Phantom types for mutable base types #128

sobolevn opened this issue Jul 14, 2021 · 1 comment · Fixed by #154
Labels
documentation Improvements or additions to documentation help wanted Extra attention is needed

Comments

@sobolevn
Copy link
Contributor

sobolevn commented Jul 14, 2021

As discussed in #127 (comment) I am openning a new issue.

This code is very risky one to write:

from django.db import models

class  User(models.Model):
    is_paid = models.BooleanField(default=False)

def is_paid_user(value: object) -> bool:
    return isinstance(value, User) and value.is_paid

class PaidUser(User, Phantom, predicate=is_paid_user):
    ...  # metaclass conflict

Why? Because User is mutable. At anytime you can just user.is_paid = True | False to change its PaidUser instance check without mypy noticing the change.

We need to document this problem.

@sobolevn
Copy link
Contributor Author

Related: wemake-services/mypy-extras#103

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants