typeddjango / django-stubs

PEP-484 stubs for Django
MIT License
1.58k stars 436 forks source link

Add a lot of runtime defaults to stubs with `stubdefaulter` #2327

Closed sobolevn closed 1 month ago

sobolevn commented 1 month ago

You can do the same with:

# Install
pip install stubdefaulter no_implicit_optional

# Run
PYTHONPATH='PATH_TO_YOUR/site-packages/django' stubdefaulter -p django-stubs
no_implicit_optional django-stubs --use-union-or
sobolevn commented 1 month ago

One question; can we add stubdefaulter to CI to keep defaults populated for new changes?

typeshed does this! I will add it in the next PR, so it won't be hidden among 3000 lines diff 😆

flaeppe commented 1 month ago

Sounds great!

I suppose one way is to check git for changes after running the command. Just want to drop off a run I've used for these cases a couple of times in other CI's:

        run: |
          set -e
          <install deps>
          git add -A
          <run command>
          if [ -n "$(git status --porcelain -- <path>)" ]; then
            echo "::error::Build result differs. Run '<run command>' then commit and push any changes"
            git status --porcelain -- <path>
            exit 1
          fi

Note: replace <> marked parts with stuff for stubdefaulter

sobolevn commented 1 month ago

We have a huge list of fixed problems in stubtest:

 note: unused allowlist entry django.contrib.gis.db.models.ForeignObjectRel.__init__
note: unused allowlist entry django.contrib.gis.db.models.ManyToOneRel.__init__
note: unused allowlist entry django.contrib.gis.db.models.OneToOneRel.__init__
note: unused allowlist entry django.contrib.gis.db.models.Q.resolve_expression
note: unused allowlist entry django.contrib.gis.forms.Widget.subwidgets
note: unused allowlist entry django.core.mail.SafeMIMEMultipart.__init__
note: unused allowlist entry django.core.mail.SafeMIMEText.__init__
note: unused allowlist entry django.core.mail.message.SafeMIMEMultipart.__init__
note: unused allowlist entry django.core.mail.message.SafeMIMEText.__init__
note: unused allowlist entry django.db.migrations.graph.MigrationGraph.make_state
note: unused allowlist entry django.db.models.ForeignObjectRel.__init__
note: unused allowlist entry django.db.models.ManyToOneRel.__init__
note: unused allowlist entry django.db.models.OneToOneRel.__init__
note: unused allowlist entry django.db.models.Q.resolve_expression
note: unused allowlist entry django.db.models.fields.related.ForeignObjectRel.__init__
note: unused allowlist entry django.db.models.fields.related.ManyToOneRel.__init__
note: unused allowlist entry django.db.models.fields.related.OneToOneRel.__init__
note: unused allowlist entry django.db.models.fields.reverse_related.ForeignObjectRel.__init__
note: unused allowlist entry django.db.models.fields.reverse_related.ManyToOneRel.__init__
note: unused allowlist entry django.db.models.fields.reverse_related.OneToOneRel.__init__
note: unused allowlist entry django.db.models.query.RawQuerySet.__init__
note: unused allowlist entry django.db.models.query_utils.Q.resolve_expression
note: unused allowlist entry django.forms.Widget.subwidgets
note: unused allowlist entry django.forms.widgets.ChoiceWidget.subwidgets
note: unused allowlist entry django.forms.widgets.Widget.subwidgets
note: unused allowlist entry django.template.EngineHandler.__init__
note: unused allowlist entry django.template.utils.EngineHandler.__init__
note: unused allowlist entry django.templatetags.i18n.BlockTranslateNode.__init__
note: unused allowlist entry django.templatetags.static.PrefixNode.__init__
note: unused allowlist entry django.templatetags.static.StaticNode.__init__
Found 30 errors (checked 880 modules)
sobolevn commented 1 month ago

I suppose one way is to check git for changes after running the command.

@flaeppe I have a better idea :)

https://github.com/JelleZijlstra/stubdefaulter/pull/96

flaeppe commented 1 month ago

Yeah that's even better

adamchainz commented 1 month ago

Very nice, thank you @sobolevn .