diff --git a/course/utils.py b/course/utils.py index 8133a79f0fbedc7eee3c485cdc0cf56e501c2df5..baa1b6cb614c9838e2533491fa6f030d75f20fff 100644 --- a/course/utils.py +++ b/course/utils.py @@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -from typing import cast, Text +from typing import cast import six import datetime # noqa @@ -58,7 +58,8 @@ from course.page.base import ( # noqa # {{{ mypy if False: - from typing import Tuple, List, Iterable, Any, Optional, Union, Dict, FrozenSet # noqa + from typing import ( # noqa + Tuple, List, Iterable, Any, Optional, Union, Dict, FrozenSet, Text) from relate.utils import Repo_ish # noqa from course.models import ( # noqa Course, @@ -532,9 +533,16 @@ def get_session_grading_rule( max_points_enforced_cap = getattr_with_fallback( (rule, flow_desc), "max_points_enforced_cap", None) + try: + from typing import Text # noqa + except ImportError: + Text = None # noqa + + grade_aggregation_strategy = cast(Text, grade_aggregation_strategy) # type: ignore # noqa + return FlowSessionGradingRule( grade_identifier=grade_identifier, - grade_aggregation_strategy=cast(Text, grade_aggregation_strategy), + grade_aggregation_strategy=grade_aggregation_strategy, due=due, generates_grade=generates_grade, description=getattr(rule, "description", None), diff --git a/course/views.py b/course/views.py index 714028eeef107dbf9cd784f4133af9a698fb1547..788e9182f7ea858170a086bad520a144361e13a4 100644 --- a/course/views.py +++ b/course/views.py @@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -from typing import cast, List, Text +from typing import cast, List import datetime @@ -85,7 +85,7 @@ from course.utils import ( # noqa # {{{ for mypy if False: - from typing import Tuple, Any, Iterable, Dict, Optional # noqa + from typing import Tuple, Text, Any, Iterable, Dict, Optional # noqa from course.content import ( # noqa FlowDesc, @@ -1136,7 +1136,11 @@ def grant_exception_stage_3(pctx, participation_id, flow_id, session_id): tags = [] # type: List[Text] if hasattr(flow_desc, "rules"): - tags = cast(List[Text], getattr(flow_desc.rules, "tags", [])) + try: + from typing import Text # noqa + except ImportError: + Text = None # noqa + tags = cast(List[Text], getattr(flow_desc.rules, "tags", [])) # type: ignore # noqa # {{{ put together access rule