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

Solve issue 154: Fix wrong type for size in File. #156

Merged
merged 1 commit into from
Sep 6, 2019
Merged

Solve issue 154: Fix wrong type for size in File. #156

merged 1 commit into from
Sep 6, 2019

Conversation

wlisesrivas
Copy link
Contributor

No description provided.

@sobolevn sobolevn merged commit 0c3e06e into typeddjango:master Sep 6, 2019
@sobolevn
Copy link
Member

sobolevn commented Sep 6, 2019

Thanks!

@wlisesrivas wlisesrivas deleted the issue-154 branch September 6, 2019 07:46
voidus pushed a commit to voidus/django-stubs that referenced this pull request Apr 23, 2024
Addresses microsoft/pylance-release#3918

As currently defined, type checkers see the `Model.DoesNotExist` and `Model.MultipleObjectsReturned` exception types as being the same on all `Model` types.

I'm replacing the exception `class` declarations on `Model` with `ClassVar` so each `Model` type will have a distinct set of exception types, allowing the usage below without type checkers thinking that the later `except` clauses are unreachable.

```python
from django.db import models

class User(models.Model):
    email = models.EmailField(max_length=250)

class Notification(models.Model):
    message = models.CharField(max_length=250)

class Media(models.Model):
    file = models.FileField()

def do_things(user_id: int, notification_id: int, media_id: Media) -> None:
    try:
        user = User.objects.get(id=user_id)
        note = Notification.objects.get(id=notification_id)
        media = Media.objects.get(id=media_id)
    except User.DoesNotExist:
        raise Exception(f"User with id {user_id} does not exist.")
    except Notification.DoesNotExist:
        raise Exception(f"Notification with id {notification_id} does not exist.") # <- Pylance marks this as unreachable
    except Media.DoesNotExist:
        raise Exception("Example exception") # <- Pylance marks this as unreachable
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants