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

Minor typing improvements [FC-0083] #285

Merged
merged 1 commit into from
Mar 6, 2025
Merged
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
2 changes: 1 addition & 1 deletion openedx_learning/apps/authoring/components/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def _get_component_version_info_headers(component_version: ComponentVersion) ->
"X-Open-edX-Component-Uuid": component.uuid,
# Component Version
"X-Open-edX-Component-Version-Uuid": component_version.uuid,
"X-Open-edX-Component-Version-Num": component_version.version_num,
"X-Open-edX-Component-Version-Num": str(component_version.version_num),
# Learning Package
"X-Open-edX-Learning-Package-Key": learning_package.key,
"X-Open-edX-Learning-Package-Uuid": learning_package.uuid,
Expand Down
2 changes: 1 addition & 1 deletion openedx_learning/apps/authoring/components/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ComponentsConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
label = "oel_components"

def ready(self):
def ready(self) -> None:
"""
Register Component and ComponentVersion.
"""
Expand Down
4 changes: 2 additions & 2 deletions openedx_learning/apps/authoring/components/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class ComponentType(models.Model):
),
]

def __str__(self):
def __str__(self) -> str:
return f"{self.namespace}:{self.name}"


Expand Down Expand Up @@ -190,7 +190,7 @@ class Meta:
verbose_name = "Component"
verbose_name_plural = "Components"

def __str__(self):
def __str__(self) -> str:
return f"{self.component_type.namespace}:{self.component_type.name}:{self.local_key}"


Expand Down
2 changes: 1 addition & 1 deletion openedx_learning/apps/authoring/contents/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class Meta:
),
]

def __str__(self):
def __str__(self) -> str:
base = f"{self.type}/{self.sub_type}"
if self.suffix:
return f"{base}+{self.suffix}"
Expand Down
15 changes: 8 additions & 7 deletions openedx_learning/apps/authoring/publishing/model_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
from __future__ import annotations

from datetime import datetime
from functools import cached_property

from django.core.exceptions import ImproperlyConfigured
Expand Down Expand Up @@ -49,15 +50,15 @@ def versioning(self):
return self.VersioningHelper(self)

@property
def uuid(self):
def uuid(self) -> str:
return self.publishable_entity.uuid

@property
def key(self):
def key(self) -> str:
return self.publishable_entity.key

@property
def created(self):
def created(self) -> datetime:
return self.publishable_entity.created

@property
Expand Down Expand Up @@ -311,19 +312,19 @@ def get_queryset(self) -> QuerySet:
)

@property
def uuid(self):
def uuid(self) -> str:
return self.publishable_entity_version.uuid

@property
def title(self):
def title(self) -> str:
return self.publishable_entity_version.title

@property
def created(self):
def created(self) -> datetime:
return self.publishable_entity_version.created

@property
def version_num(self):
def version_num(self) -> int:
return self.publishable_entity_version.version_num

class Meta:
Expand Down
2 changes: 1 addition & 1 deletion openedx_learning/apps/authoring/publishing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
]


class LearningPackage(models.Model): # type: ignore[django-manager-missing]
class LearningPackage(models.Model):
"""
Top level container for a grouping of authored content.

Expand Down
2 changes: 1 addition & 1 deletion openedx_learning/contrib/media_server/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MediaServerConfig(AppConfig):
verbose_name = "Learning Core: Media Server"
default_auto_field = "django.db.models.BigAutoField"

def ready(self):
def ready(self) -> None:
if not settings.DEBUG:
# Until we get proper security and support for running this app
# under a separate domain, just don't allow it to be run in
Expand Down
2 changes: 1 addition & 1 deletion openedx_learning/lib/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.utils.translation import gettext_lazy as _


def validate_utc_datetime(dt: datetime):
def validate_utc_datetime(dt: datetime) -> None:
if dt.tzinfo != timezone.utc:
raise ValidationError(
_("The timezone for %(datetime)s is not UTC."),
Expand Down
4 changes: 2 additions & 2 deletions openedx_tagging/core/tagging/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ def get_object_tags(
)
if not include_deleted:
# Exclude if the whole taxonomy was deleted
base_qs = base_qs.exclude(taxonomy_id=None) # type: ignore
base_qs = base_qs.exclude(taxonomy=None)
# Exclude if just the tag is deleted
base_qs = base_qs.exclude(tag_id=None, taxonomy__allow_free_text=False) # type: ignore
base_qs = base_qs.exclude(tag=None, taxonomy__allow_free_text=False)
tags = (
base_qs
# Preload related objects, including data for the "get_lineage" method on ObjectTag/Tag:
Expand Down
2 changes: 1 addition & 1 deletion openedx_tagging/core/tagging/rest_api/v1/permissions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Tagging permissions
"""
import rules # type: ignore[import]
import rules
from rest_framework.permissions import DjangoObjectPermissions

from ...models import Tag, Taxonomy
Expand Down
3 changes: 1 addition & 2 deletions openedx_tagging/core/tagging/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
from typing import Callable, Union

import django.contrib.auth.models
# typing support in rules depends on https://github.com/dfunckt/django-rules/pull/177
import rules # type: ignore[import]
import rules
from attrs import define

from .models import Tag, Taxonomy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import datetime, timezone

from django.contrib.auth import get_user_model
from django.contrib.auth.models import User as UserType # pylint: disable=imported-auth-user
Copy link
Contributor

Choose a reason for hiding this comment

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

Boo.. too bad we have to trade a mypy ignore for a pylint ignore.

from django.core.exceptions import ObjectDoesNotExist, ValidationError
from freezegun import freeze_time

Expand Down Expand Up @@ -213,7 +214,7 @@ class CollectionEntitiesTestCase(CollectionsTestCase):
"""
published_component: Component
draft_component: Component
user: User # type: ignore [valid-type]
user: UserType
html_type: ComponentType
problem_type: ComponentType

Expand Down
3 changes: 2 additions & 1 deletion tests/openedx_learning/apps/authoring/components/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import datetime, timezone

from django.contrib.auth import get_user_model
from django.contrib.auth.models import User as UserType # pylint: disable=imported-auth-user
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from freezegun import freeze_time

Expand Down Expand Up @@ -541,7 +542,7 @@ class SetCollectionsTestCase(ComponentTestCase):
collection2: Collection
collection3: Collection
published_problem: Component
user: User # type: ignore [valid-type]
user: UserType

@classmethod
def setUpTestData(cls) -> None:
Expand Down
3 changes: 1 addition & 2 deletions tests/openedx_tagging/core/tagging/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from urllib.parse import parse_qs, quote_plus, urlparse

import ddt # type: ignore[import]
# typing support in rules depends on https://github.com/dfunckt/django-rules/pull/177
import rules # type: ignore[import]
import rules
from django.contrib.auth import get_user_model
from django.core.files.uploadedfile import SimpleUploadedFile
from rest_framework import status
Expand Down