11from collections import OrderedDict
22from itertools import islice
3+ from typing import Union
34
45from django .core .exceptions import ImproperlyConfigured
56from django .urls import reverse
@@ -23,7 +24,7 @@ class Library:
2324 def __init__ (self ):
2425 self .columns = []
2526
26- def register (self , column ):
27+ def register (self , column : "Column" ):
2728 if not hasattr (column , "from_field" ):
2829 raise ImproperlyConfigured (f"{ column .__class__ .__name__ } is not a subclass of Column" )
2930 self .columns .append (column )
@@ -68,7 +69,13 @@ class LinkTransform:
6869 accessor = None
6970 attrs = None
7071
71- def __init__ (self , url = None , accessor = None , attrs = None , reverse_args = None ):
72+ def __init__ (
73+ self ,
74+ url : Union [callable , None ] = None ,
75+ accessor : Union [str , Accessor , None ] = None ,
76+ attrs : Union [dict , None ] = None ,
77+ reverse_args : Union [list , tuple , None ] = None ,
78+ ):
7279 """
7380 arguments:
7481 url (callable): If supplied, the result of this callable will be used as ``href`` attribute.
@@ -95,7 +102,7 @@ def __init__(self, url=None, accessor=None, attrs=None, reverse_args=None):
95102
96103 self .reverse_args = reverse_args or {}
97104
98- def compose_url (self , ** kwargs ):
105+ def compose_url (self , ** kwargs ) -> str :
99106 if self .url and callable (self .url ):
100107 return call_with_appropriate (self .url , kwargs )
101108
@@ -119,10 +126,8 @@ def compose_url(self, **kwargs):
119126 )
120127 return context .get_absolute_url ()
121128
122- def call_reverse (self , record ):
123- """
124- Prepares the arguments to reverse() for this record and calls reverse()
125- """
129+ def call_reverse (self , record ) -> str :
130+ """Prepares the arguments to reverse() for this record and calls reverse()."""
126131
127132 def resolve_if_accessor (val ):
128133 return val .resolve (record ) if isinstance (val , Accessor ) else val
@@ -399,7 +404,7 @@ def order(self, queryset, is_descending):
399404 return (queryset , False )
400405
401406 @classmethod
402- def from_field (cls , field , ** kwargs ) -> "Column | None" :
407+ def from_field (cls , field , ** kwargs ) -> "Union[ Column, None] " :
403408 """
404409 Return a specialized column for the model field or `None`.
405410
0 commit comments