Hi, I've done a little googling but couldn't find anything relevant, apologies if I've overlooked.
I'm looking to integrate mypy with django stubs into our mono-repo via sticklerci, and I don't know what I should be doing for the
django_settings_module setting -- since it will be a different file depending on which project(s) it's running on.
my_field: ManualType = some_library.fields.CustomField()
Hi folks, quick question (I'm relatively new to typed Python):
Why is the package named with a hyphen -
rest_framework-stubs? I want to do something like the below:
from rest_framework-stubs.response import Response resp: Response = c.get('/')
The problem here is that
rest_framework-stubs is an illegal import due to the hyphen.
What's going on? Should I even be using the stubs in this way?
from rest_framework.response import Response resp: Response = c.get('/')
Manager[MyModel]should be quoted as
'Manager[MyModel]'to avoid a type error, but this is not possible when subclassing. For example, I want to create a subclass
class MyUserManager(BaseUserManager[MyUser]), but this triggers a TypeError. I cannot put it in quotes since it's inside the class definition. Is there any workaround while we wait for pull request 12405?
django.apps. Or can I use a stub of
MyUserto avoid importing
user: ??? = apps.get_model('auth', 'MyUser')
Hello guys, I got this error while trying to run pytest:
~/P/django-stubs ❯❯❯ pytest ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...] pytest: error: unrecognized arguments: --mypy-ini-file=./test-data/plugins.ini --mypy-extension-hook=scripts.tests_extension_hook.django_plugin_hook inifile: /Users/kacperszmigiel/Projects/django-stubs/pytest.ini rootdir: /Users/kacperszmigiel/Projects/django-stubs
Has anyone encountered this error and knows a fix?
*_idsyntax to access foreign key IDs. Does django-stubs support typing for such expressions?
[foreign_key]_idfield hint for every
ForeignKeyin every model, but even then I'm not sure what the appropriate type hint should be.
So, this is hard to explain:
from django.contrib.auth.models import Group from django.db import models class MyGroup(Group): pass class User(models.Model): groups = models.ManyToManyField(MyGroup) group = MyGroup() user = User() reveal_type(MyGroup.permissions) reveal_type(group.permissions) reveal_type(user.groups)
mypy-test.py:13: note: Revealed type is 'django.db.models.fields.related_descriptors.ManyToManyDescriptor' mypy-test.py:14: note: Revealed type is 'django.db.models.manager.RelatedManager*[django.contrib.auth.models.Permission]' mypy-test.py:15: note: Revealed type is 'Any'
Any idea what's happening here?