Skip to content

Commit dff7730

Browse files
refactor: use 'type' keyword instead of TypeAlias
1 parent fd53a1d commit dff7730

8 files changed

Lines changed: 18 additions & 18 deletions

File tree

src/openedx_content/applets/components/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"""
1818
from __future__ import annotations
1919

20-
from typing import ClassVar, NewType, TypeAlias, cast
20+
from typing import ClassVar, NewType, cast
2121

2222
from django.db import models
2323
from typing_extensions import deprecated
@@ -133,7 +133,7 @@ class Component(PublishableEntityMixin):
133133
that will exist for as long as the LearningPackage itself exists.
134134
"""
135135

136-
ID: TypeAlias = ComponentID
136+
type ID = ComponentID
137137

138138
@property
139139
def id(self) -> ComponentID:

src/openedx_content/applets/containers/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from __future__ import annotations
66

77
from functools import cached_property
8-
from typing import NewType, TypeAlias, cast, final
8+
from typing import NewType, cast, final
99

1010
from django.core.exceptions import ValidationError
1111
from django.db import models
@@ -165,7 +165,7 @@ class Container(PublishableEntityMixin):
165165
entities for different learners or at different times.
166166
"""
167167

168-
ID: TypeAlias = ContainerID
168+
type ID = ContainerID
169169

170170
type_code: str # Subclasses must override this, e.g. "unit"
171171
# olx_code: the OLX <tag_name> for XML serialization. Subclasses _may_ override this.

src/openedx_content/applets/publishing/models/learning_package.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
LearningPackage model
33
"""
44

5-
from typing import NewType, TypeAlias
5+
from typing import NewType
66

77
from django.db import models
88
from typing_extensions import deprecated
@@ -30,9 +30,9 @@ class LearningPackage(models.Model):
3030
# uniqueness indexes on those foreign keys + their own fields, so the 4
3131
# bytes saved will add up over time.
3232
LearningPackageID = NewType("LearningPackageID", int)
33-
ID: TypeAlias = LearningPackageID
33+
type ID = LearningPackageID
3434

35-
class IDField(TypedBigAutoField[LearningPackageID]):
35+
class IDField(TypedBigAutoField[ID]):
3636
pass
3737

3838
id = IDField(primary_key=True)

src/openedx_content/applets/publishing/models/publishable_entity.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from datetime import datetime
88
from functools import cached_property
9-
from typing import ClassVar, NewType, Self, TypeAlias
9+
from typing import ClassVar, NewType, Self
1010

1111
from django.conf import settings
1212
from django.core.exceptions import ImproperlyConfigured
@@ -113,9 +113,9 @@ class PublishableEntity(models.Model):
113113
more convenient, like file access.
114114
"""
115115
PublishableEntityID = NewType("PublishableEntityID", int)
116-
ID: TypeAlias = PublishableEntityID
116+
type ID = PublishableEntityID
117117

118-
class IDField(TypedBigAutoField[PublishableEntityID]):
118+
class IDField(TypedBigAutoField[ID]):
119119
pass
120120

121121
id = IDField(primary_key=True)

src/openedx_content/applets/sections/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Models that implement sections
33
"""
44

5-
from typing import NewType, TypeAlias, cast, override
5+
from typing import NewType, cast, override
66

77
from django.core.exceptions import ValidationError
88
from django.db import models
@@ -29,7 +29,7 @@ class Section(Container):
2929
entities and can be added to other containers.
3030
"""
3131

32-
ID: TypeAlias = SectionID
32+
type ID = SectionID
3333

3434
type_code = "section"
3535
olx_tag_name = "chapter" # Serializes to OLX as `<chapter>...</chapter>`.

src/openedx_content/applets/subsections/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Models that implement subsections
33
"""
44

5-
from typing import NewType, TypeAlias, cast, override
5+
from typing import NewType, cast, override
66

77
from django.core.exceptions import ValidationError
88
from django.db import models
@@ -29,7 +29,7 @@ class Subsection(Container):
2929
entities and can be added to other containers.
3030
"""
3131

32-
ID: TypeAlias = SubsectionID
32+
type ID = SubsectionID
3333

3434
type_code = "subsection"
3535
olx_tag_name = "sequential" # Serializes to OLX as `<sequential>...</sequential>`.

src/openedx_content/applets/units/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Models that implement units
33
"""
44

5-
from typing import NewType, TypeAlias, cast, override
5+
from typing import NewType, cast, override
66

77
from django.core.exceptions import ValidationError
88
from django.db import models
@@ -27,7 +27,7 @@ class Unit(Container):
2727
entities and can be added to other containers.
2828
"""
2929

30-
ID: TypeAlias = UnitID
30+
type ID = UnitID
3131

3232
type_code = "unit"
3333
olx_tag_name = "vertical" # Serializes to OLX as `<unit>...</unit>`.

src/openedx_django_lib/id_fields.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ class TypedBigAutoField(models.BigAutoField):
1313
```
1414
class MyModel(models.Model):
1515
MyModelID = NewType("MyModelID", int)
16-
ID: TypeAlias = MyModelID
16+
type ID = MyModelID
1717
18-
class IDField(TypedBigAutoField[MyModelID]):
18+
class IDField(TypedBigAutoField[ID]):
1919
pass
2020
2121
id = IDField(primary_key=True)

0 commit comments

Comments
 (0)