-
Notifications
You must be signed in to change notification settings - Fork 286
Django models.TextChoices is not-indexable? #1048
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
Comments
Thanks for the report, and sorry for taking so long to respond - I somehow missed the notification for this. This looks like another consequence of not supporting #151 - pytype doesn't have stubs for django, so types are treated as Any, and I'm going to leave this open as a separate issue, since (1) django is a widely used library and we should verify that this works once pytype has type information available and (2) there are possibly other ways to resolve this (such as allowing anything that inherits from |
@rchen152 from django.db.models.enums import Choices
class ReportCategoryChoices(models.TextChoices):
A = "A", _("a")
B = "B", _("b")
C = "C", _("c")
ReportCategoryChoices: Type[Choices] = ReportCategoryChoices |
I have also encountered this issue. Providing $ pytype --version
2022.08.23
from django.db.models import TextChoices
class Choices(TextChoices):
ONE = 1
TWO = 2
print(Choices["ONE"]) $ pytype bad.py
Computing dependencies
Analyzing 1 sources with 0 local dependencies
ninja: Entering directory `.pytype'
[1/1] check bad
FAILED: [redacted]/.pytype/pyi/bad.pyi
/usr/local/bin/python -m pytype.single --imports_info [redacted]/.pytype/imports/bad.imports --module-name bad --platform linux -V 3.10 -o [redacted]/.pytype/pyi/bad.pyi --analyze-annotated --nofail --quick [redacted]/bad.py
File "[redacted]/bad.py", line 9, in <module>: class Choices is not indexable [not-indexable]
('Choices' does not subclass Generic)
For more details, see https://google.github.io/pytype/errors.html#not-indexable
ninja: build stopped: subcommand failed.
Leaving directory '.pytype'
from enum import Enum
from django.db.models import TextChoices
class Choices(TextChoices, Enum):
ONE = 1
TWO = 2
print(Choices["ONE"]) $ pytype good.py
Computing dependencies
Analyzing 1 sources with 0 local dependencies
ninja: Entering directory `.pytype'
ninja: no work to do.
Leaving directory '.pytype'
Success: no errors found |
* Replace Optional typing by | None * Replace get_project_field method by project_field attribute * Allow the execution of integrations per finding and per execution * Allow BaseInput parsing in a declarative way * Fix flake8 and pytype issues * Fix create_finding typing * Fix typing * Workaround to fix issues reported by pytype on TextChoices * Fix typing of Gitleaks executor on Gitleaks parser * Workaround to fix issues reported by pytype on TextChoices * Fix issues on cmseek and gitleaks executor and/or parsers * Disable pytype when accessing dynamic attributes of CONFIG class * Try to fix pytype issue when calling lower over an string from a dict * Disable pytype when accessing dynamic attributes of CONFIG class * Fix typing issue * Fix typing issue on load_report_as_json method * Fix some typing issues * Fix return type from load_report_as_json * Ignore pytype attribute error * Fix method signature * Fix return type * Remove mypy ignores * Remove flake8 ignores * Fix pytype and flake8 issues * Fix typing * Fix typing * Fix typing * Fix typing * Fix typing * Fix typing * Fix typing * exclude unit tests from strict typing check * fix pytype execution on cicd * fix typing in telegram BaseMixin * fix typing issues * fix typing issues * remove tests exclusion * ignore pytype false positives in tests * fix typing issues * always return a model for _get_model method * fix some issues on unit tests * test if unit tests work without extending Enum in all the Django choices (google/pytype#1048) * try another approach to avoid error google/pytype#1048 while not breaking the code * fix unit tests for defectdojo integration * fix unit tests for tool executor
I made project with django and I applied type-hinting by using pytype. But pytype gives me type-error like this
type_test.py
and here is the ReportCategoryClass
in django ReportCategoryClass is Indexable. why did pytype say ReportCategory is not indexable?
The text was updated successfully, but these errors were encountered: