Politikon icon indicating copy to clipboard operation
Politikon copied to clipboard

Use Python 3.6 and Use Type Hinting

Open mikaeilorfanian opened this issue 7 years ago • 0 comments

I noticed docstrings in the code that duplicate the "type hinting" feature of Python 3.5 and higher. Below is an example of how type hinting can produce clean and easy-to-read code:

# current version
def get_object(self, queryset=None):
       """
       Get page for specified language
       :param queryset: current queryset
       :type queryset: QuerySet
       :return: instance of Page
       :rtype: Page
       """ 

# after using type hinting
from django.db.models.query import QuerySet

from .models import Page

def get_object(self, queryset=None: QuerySet) -> Page:
     pass

Using type hinting also allows us to use static code analyzers which will help us produce less buggy code.

mikaeilorfanian avatar Sep 02 '17 10:09 mikaeilorfanian