diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f605f8af..1b932fb5 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,8 @@ +# 2.5.1 + +* Fixed - py.typed file wasn't installed properly via setuptools. +* Added type hints for the OpaqueKeyField subclasses (requires mypy plugin) + # 2.5.0 * Added python type hints diff --git a/MANIFEST.in b/MANIFEST.in index d75a27df..86cebd6c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -6,4 +6,4 @@ include requirements/django.in recursive-include opaque_keys *.html *.png *.gif *js *.css *jpg *jpeg *svg *py include requirements/constraints.txt include requirements/base.txt - +include opaque_keys/py.typed diff --git a/opaque_keys/__init__.py b/opaque_keys/__init__.py index 64e88a4e..1b7fec68 100644 --- a/opaque_keys/__init__.py +++ b/opaque_keys/__init__.py @@ -14,7 +14,7 @@ from stevedore.enabled import EnabledExtensionManager from typing_extensions import Self # For python 3.11 plus, can just use "from typing import Self" -__version__ = '2.5.0' +__version__ = '2.5.1' class InvalidKeyError(Exception): diff --git a/opaque_keys/edx/django/models.py b/opaque_keys/edx/django/models.py index 4effd974..d9ed7372 100644 --- a/opaque_keys/edx/django/models.py +++ b/opaque_keys/edx/django/models.py @@ -194,6 +194,12 @@ 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. + # See https://github.com/typeddjango/django-stubs/blob/6a850f6/django-stubs/db/models/fields/__init__.pyi#L503-L511 + # for examples of how this works for the standard field types in the upstream codebase. + # Note that these particular type annotations have no effect at runtime nor on Django itself nor on PyLance. + _pyi_private_set_type: LearningContextKey | str | None # The types that you can set into this field. + _pyi_private_get_type: LearningContextKey | None # The type that you get when you read from this field class CourseKeyField(OpaqueKeyField): @@ -202,6 +208,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 | None class UsageKeyField(OpaqueKeyField): @@ -210,6 +219,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 | None class LocationKeyField(UsageKeyField): @@ -228,3 +240,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 | None