Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type information #82

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion autoslug/fields.py

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Instance properties initialised in __init__ are not typed
  • args and kwargs are untyped, so __init__ needs to return -> None

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#

# django
from typing import Any, Dict, List, Tuple

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused imports

from django.conf import settings
from django.db.models.fields import SlugField
from django.db.models.signals import post_save
Expand Down Expand Up @@ -250,7 +251,7 @@ def deconstruct(self):

return name, path, args, kwargs

def pre_save(self, instance, add):
def pre_save(self, instance, add) -> str | None:

# get currently entered slug
value = self.value_from_object(instance)
Expand Down
Empty file added autoslug/py.typed
Empty file.
3 changes: 2 additions & 1 deletion autoslug/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
.. _modeltranslation: http://django-modeltranslation.readthedocs.org

"""
from typing import Callable
from django.conf import settings
from django import VERSION

Expand All @@ -68,7 +69,7 @@

# use custom slugifying function if any
slugify_function_path = getattr(settings, 'AUTOSLUG_SLUGIFY_FUNCTION', 'autoslug.utils.slugify')
slugify = get_callable(slugify_function_path)
slugify: Callable[[str], str] = get_callable(slugify_function_path)

# enable/disable modeltranslation support
autoslug_modeltranslation_enable = getattr(settings, 'AUTOSLUG_MODELTRANSLATION_ENABLE', False)
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
name = 'django-autoslug',
version = __version__,
packages = ['autoslug'],
package_data={'autoslug': ['py.typed']},

requires = ['python (>= 3.5)', 'django (>= 1.11)'],
# in case you want to use slugify() with support for transliteration:
Expand Down