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

Field as a part of a union seems to be broken #692

Closed
budziam opened this issue Aug 12, 2021 · 1 comment
Closed

Field as a part of a union seems to be broken #692

budziam opened this issue Aug 12, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@budziam
Copy link

budziam commented Aug 12, 2021

Bug report

What's wrong

Django model Field value as a part of a union results in unexpected behavior. Please find the following example:

from typing import Union
from uuid import UUID

from django.db import models


class User(models.Model):
    uuid = models.UUIDField()


class AnonymousUser:
    uuid: UUID


def example(value: UUID) -> None:
    ...


user_only: User = User()
anonymous_only: AnonymousUser = AnonymousUser()
union_value: Union[AnonymousUser, User] = User()

example(user_only.uuid)
example(anonymous_only.uuid)
example(union_value.uuid)

It causes the following error

test.py:25: error: Argument 1 to "example" has incompatible type "Union[UUID, UUIDField[Union[str, UUID], UUID]]"; expected "UUID"

How is that should be

No error should be raised.

System information

  • OS: macos
  • python version: 3.8.9
  • django version: 3.2.6
  • mypy version: 0.910
  • django-stubs version: 1.8.0
@budziam budziam added the bug Something isn't working label Aug 12, 2021
@flaeppe
Copy link
Member

flaeppe commented Sep 24, 2023

This is an upstream problem for classes with descriptors, ref: python/mypy#5570 (comment)

I'm gonna close this in favour of the mypy issue.

@flaeppe flaeppe closed this as not planned Won't fix, can't repro, duplicate, stale Sep 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants