Skip to content

Commit 19294ae

Browse files
committed
Fix type validation in APISettings.get_setting for type safety
Break long lines to comply with PEP 8
1 parent e67f577 commit 19294ae

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

django_api_versioning/decorators.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,16 @@ def endpoint(
2020
- Ensures that no version lower than `API_MIN_VERSION` is registered.
2121
2222
Args:
23-
postfix (str): The endpoint suffix (e.g., "users" → "api/v1/users").
24-
version (Optional[int]): The version of the API. Defaults to None (unversioned).
25-
backward (bool): If True, registers routes for all versions from `API_MIN_VERSION` up to the current version, which is less than or equal to `API_MAX_VERSION`. Defaults to True.
26-
app_name (Optional[str]): The app name to be prefixed to the route.
23+
postfix (str): The endpoint suffix (e.g., "users" →
24+
"api/v1/users").
25+
version (Optional[int]): The version of the API. Defaults
26+
to None (unversioned).
27+
backward (bool): If True, registers routes for all versions
28+
from `API_MIN_VERSION` up to the current
29+
version, which is less than or equal to
30+
`API_MAX_VERSION`. Defaults to True.
31+
app_name (Optional[str]): The app name to be prefixed to
32+
the route.
2733
view_name (Optional[str]): The custom view name for Django.
2834
2935
Returns:

django_api_versioning/settings.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
from django.conf import settings
33
from django.core.exceptions import ImproperlyConfigured
44
from dataclasses import dataclass
5-
from typing import Optional
5+
from typing import Optional, Any
66
from .exceptions import VersionTypeError, VersionRangeError, VersioningError
77

88
# Initialize logger
99
logger = logging.getLogger(__name__)
1010

1111
@dataclass
1212
class APISettings:
13-
13+
1414
API_BASE_PATH: str = "api/v{version}/"
1515
API_MAX_VERSION: int = 1
1616
API_MIN_VERSION: int = 1
1717
ROOT_URLCONF: str = 'django_api_versioning.urls'
1818

1919
@staticmethod
20-
def get_setting(name: str, default: Optional[any] = None) -> Optional[any]:
20+
def get_setting(name: str, default: Optional[Any] = None) -> Any:
2121
"""
2222
Reads the setting from Django settings and provides a default if not found.
2323
"""
@@ -30,9 +30,7 @@ def __post_init__(self):
3030

3131
# Ensure that API_BASE_PATH ends with a "/"
3232
if not self.API_BASE_PATH.endswith("/"):
33-
logger.warning(
34-
"API_BASE_PATH should end with a '/'. Adding '/' automatically."
35-
)
33+
logger.warning("API_BASE_PATH should end with a '/'. Adding '/' automatically.")
3634
self.API_BASE_PATH += "/"
3735

3836
# Validate version settings

setup.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88
version="0.1.0",
99
author="Mojtaba Arvin",
1010
author_email="ArvinDevDay@gmail.com",
11-
description="A powerful and flexible library for managing API versioning in Django projects.",
11+
description= (
12+
"Django API versioning decorator provides a solution "
13+
"for managing multiple API versions within "
14+
"the Django framework, enabling versioning "
15+
"through URLs with backward compatibility "
16+
"and automatically registering routes."
17+
),
1218
long_description=long_description,
1319
long_description_content_type="text/markdown",
1420
url="https://github.com/mojtaba-arvin/django-api-versioning",

0 commit comments

Comments
 (0)