How do django Field type hints work?

26 views
Skip to first unread message

Justin Black

unread,
Sep 23, 2022, 6:57:11 PM9/23/22
to Django users
Hello there,

If I have a model:

class Money(models.Model):
    price = models.DecimalField()

m = Money(...)
pycharm knows that m.price is of type Decimal but when I read through the django code base, I don't see DecimalField or Field subclassing decimal.Decimal
And I don't see any registration code that registers DecimalField as type Decimal

How does django do this?

Mohammad Anarul

unread,
Sep 23, 2022, 11:36:02 PM9/23/22
to django...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2b1d5103-7aa4-4882-b1a8-f88ec43293d2n%40googlegroups.com.

Justin Black

unread,
Sep 24, 2022, 1:03:29 AM9/24/22
to django...@googlegroups.com
That article doesn't explain where and how the DecimalField class describes its type as Decimal to python and pycharm. What line does that? 

You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/IDkt5miBpA0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAE59x8e_8AJsuM%3D4PYNvJecb-hy2wAXvV7N0%2BkjewqJxPw_LNQ%40mail.gmail.com.

Muhammad Juwaini Abdul Rahman

unread,
Sep 25, 2022, 9:28:23 AM9/25/22
to django...@googlegroups.com
My pycharm shows DecimalField as type Any.

--
Reply all
Reply to author
Forward
0 new messages