From 91275639b4be2ff4e2df04e25bc3f5b46cb9e02a Mon Sep 17 00:00:00 2001 From: dzhuang Date: Tue, 12 Sep 2017 13:38:51 +0800 Subject: [PATCH] ImportError for typing.Text PY3.5 (win). followed #306 --- course/utils.py | 14 +++++++++++--- course/views.py | 10 +++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/course/utils.py b/course/utils.py index 8133a79f..baa1b6cb 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 714028ee..788e9182 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 -- GitLab