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

Beginner questions #186

Open
rvanlaar opened this issue Aug 28, 2023 · 2 comments
Open

Beginner questions #186

rvanlaar opened this issue Aug 28, 2023 · 2 comments

Comments

@rvanlaar
Copy link

rvanlaar commented Aug 28, 2023

Started using Pyright and VScode. Used mypy a lot, but since typing support in VSCode is done via pyright, here I am.

Is there a recommend pyright config?

On my Django models I have a class Meta defined and there's an error that:
"Meta" overrides symbol of same name in class "Model"... reportIncompatibleVariableOverride

Didn't see it mentioned in the documentation. Is there a recommended way to handle this?

I have multiple choices.
Example:

class study(models.Model):
    LEVEL_CHOICES = (
        ("e", _("Elementary"),
        ("h", _("HighSchool")
    )
    level = models.CharField(
        max_length=1
        choices= LEVEL_CHOICES,
        blank= True)

    def info(self):
        return "%s" % self.get_level_display() # ReportUnkownMemberType and ReportGeneralTypeIssues

What's the recommended solution?

@rvanlaar rvanlaar changed the title How to handle: "Meta" overrides symbol of same name in class "Model" Beginner questions Aug 28, 2023
@sbdchd
Copy link
Owner

sbdchd commented Aug 28, 2023

Hmm good question, I'm not super familiar with using Pyright for type checking, I usually use it for autocomplete and run mypy in CI, but:

  1. might just have to ignore it
  2. I think you could manually write a definition for get_level_display inline?

Like:

class study(models.Model):
    LEVEL_CHOICES = (
        ("e", _("Elementary"),
        ("h", _("HighSchool")
    )
    level = models.CharField(
        max_length=1
        choices= LEVEL_CHOICES,
        blank= True)
    if TYPING:
        def get_level_display(self) -> SomeTypeHereIDK: ...

    def info(self):
        return "%s" % self.get_level_display() # ReportUnkownMemberType and ReportGeneralTypeIssues

tricky part of Django ORM are these generated / metaprogrammed/ monkey patched things that can't be expressed statically

@rvanlaar
Copy link
Author

Appreciate the response.

After trying django-types and pyright on a branch, I decided against going further with it.

The application I'm working on relies on the meta programmed parts. I don't see django-types helping me. Instead I have to sprinkle the models everywhere with backlinks, autogenerated functions, 'id' and more.

Especially since django-stubs knows how to do it.

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

No branches or pull requests

2 participants