Skip to content

Commit

Permalink
feat: Add smart type hints to OpaqueKeyField and its subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenmacdonald committed Aug 25, 2023
1 parent c9e6007 commit 55cd73a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions opaque_keys/edx/django/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ class LearningContextKeyField(OpaqueKeyField):
"""
description = "A LearningContextKey object, saved to the DB in the form of a string"
KEY_CLASS = LearningContextKey
# Declare the field types for the django-stubs mypy type hint plugin:
_pyi_private_set_type: LearningContextKey | str | None
_pyi_private_get_type: LearningContextKey


class CourseKeyField(OpaqueKeyField):
Expand All @@ -202,6 +205,9 @@ class CourseKeyField(OpaqueKeyField):
"""
description = "A CourseKey object, saved to the DB in the form of a string"
KEY_CLASS = CourseKey
# Declare the field types for the django-stubs mypy type hint plugin:
_pyi_private_set_type: CourseKey | str | None
_pyi_private_get_type: CourseKey


class UsageKeyField(OpaqueKeyField):
Expand All @@ -210,6 +216,9 @@ class UsageKeyField(OpaqueKeyField):
"""
description = "A Location object, saved to the DB in the form of a string"
KEY_CLASS = UsageKey
# Declare the field types for the django-stubs mypy type hint plugin:
_pyi_private_set_type: UsageKey | str | None
_pyi_private_get_type: UsageKey


class LocationKeyField(UsageKeyField):
Expand All @@ -228,3 +237,6 @@ class BlockTypeKeyField(OpaqueKeyField):
"""
description = "A BlockTypeKey object, saved to the DB in the form of a string."
KEY_CLASS = BlockTypeKey
# Declare the field types for the django-stubs mypy type hint plugin:
_pyi_private_set_type: BlockTypeKey | str | None
_pyi_private_get_type: BlockTypeKey

0 comments on commit 55cd73a

Please sign in to comment.