From 284ba5d8bec313f2c98849153276f923027d74b1 Mon Sep 17 00:00:00 2001 From: dzhuang Date: Sat, 8 Apr 2017 15:42:51 +0800 Subject: [PATCH] fix #306 --- course/admin.py | 5 +++-- course/auth.py | 6 ++++-- course/content.py | 12 ++++++++---- course/enrollment.py | 5 +++-- course/exam.py | 5 +++-- course/flow.py | 37 ++++++++++++++++++------------------- course/grades.py | 11 +++++++---- course/grading.py | 13 +++++++------ course/im.py | 3 ++- course/models.py | 4 ++-- course/page/base.py | 5 ++--- course/receivers.py | 3 ++- course/sandbox.py | 5 ++++- course/validation.py | 2 +- course/versioning.py | 7 ++++--- course/views.py | 11 ++++++----- relate/utils.py | 8 ++++++-- 17 files changed, 82 insertions(+), 60 deletions(-) diff --git a/course/admin.py b/course/admin.py index b75b6289..a0256372 100644 --- a/course/admin.py +++ b/course/admin.py @@ -24,8 +24,6 @@ THE SOFTWARE. import six -from typing import Any # noqa - from django.utils.translation import ( ugettext_lazy as _, string_concat, pgettext) from django.contrib import admin @@ -49,6 +47,9 @@ from course.constants import ( exam_ticket_states ) +if False: + from typing import Any # noqa + # {{{ permission helpers diff --git a/course/auth.py b/course/auth.py index 124264aa..348c2e38 100644 --- a/course/auth.py +++ b/course/auth.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, Any, Optional, Text # noqa +from typing import cast from django.utils.translation import ugettext_lazy as _, string_concat from django.shortcuts import ( # noqa render, get_object_or_404, redirect, resolve_url) @@ -61,10 +61,12 @@ from course.constants import ( from course.models import Participation, Course # noqa from accounts.models import User - from relate.utils import StyledForm, StyledModelForm from django_select2.forms import ModelSelect2Widget +if False: + from typing import Any, Optional, Text # noqa + # {{{ impersonation diff --git a/course/content.py b/course/content.py index 26dcf5fd..fb3fcb93 100644 --- a/course/content.py +++ b/course/content.py @@ -24,6 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ +from typing import cast, Union from django.conf import settings from django.utils.translation import ugettext as _ @@ -58,11 +59,10 @@ else: # {{{ mypy -from typing import ( # noqa - cast, Union, Any, List, Tuple, Optional, Callable, Text, Dict) - if False: # for mypy + from typing import ( # noqa + Any, List, Tuple, Optional, Callable, Text, Dict) from course.models import Course, Participation # noqa import dulwich # noqa from course.validation import ValidationContext # noqa @@ -1090,7 +1090,11 @@ def parse_date_spec( return localize_if_needed( datetime.datetime.combine(datespec, datetime.time.min)) - datespec_str = cast(Text, datespec).strip() + try: + from typing import Text + except ImportError: + Text = None # noqa + datespec_str = cast(Text, datespec).strip() # type: ignore # {{{ parse postprocessors diff --git a/course/enrollment.py b/course/enrollment.py index b5bb5a1a..b7e99e92 100644 --- a/course/enrollment.py +++ b/course/enrollment.py @@ -71,8 +71,9 @@ from pytools.lex import RE as REBase # noqa # {{{ for mypy -from typing import Any, Tuple, Text, Optional, List # noqa -from course.utils import CoursePageContext # noqa +if False: + from typing import Any, Tuple, Text, Optional, List # noqa + from course.utils import CoursePageContext # noqa # }}} diff --git a/course/exam.py b/course/exam.py index a714f28f..2470061d 100644 --- a/course/exam.py +++ b/course/exam.py @@ -63,8 +63,9 @@ from relate.utils import StyledForm # {{{ mypy -import datetime # noqa -from typing import Optional, Text, Tuple, FrozenSet # noqa +if False: + import datetime # noqa + from typing import Optional, Text, Tuple, FrozenSet # noqa # }}} diff --git a/course/flow.py b/course/flow.py index bbd4d036..a00af1b3 100644 --- a/course/flow.py +++ b/course/flow.py @@ -63,6 +63,7 @@ from course.constants import ( flow_session_interaction_kind ) from course.models import ( + Participation, FlowSession, FlowPageData, FlowPageVisit, FlowPageVisitGrade, get_feedback_for_grade, @@ -86,25 +87,23 @@ from relate.utils import retry_transaction_decorator # {{{ mypy -from typing import Any, Optional, Iterable, Tuple, Text, List # noqa -import datetime # noqa -from course.models import ( # noqa - Course, - Participation - ) -from course.utils import ( # noqa - CoursePageContext, - FlowSessionStartRule, - ) -from course.content import ( # noqa - FlowDesc, - ) -from course.page.base import ( # noqa - PageBase, - PageBehavior, - AnswerFeedback - ) -from relate.utils import Repo_ish # noqa +if False: + from typing import Any, Optional, Iterable, Tuple, Text, List # noqa + import datetime # noqa + from course.models import Course # noqa + from course.utils import ( # noqa + CoursePageContext, + FlowSessionStartRule, + ) + from course.content import ( # noqa + FlowDesc, + ) + from course.page.base import ( # noqa + PageBase, + PageBehavior, + AnswerFeedback + ) + from relate.utils import Repo_ish # noqa # }}} diff --git a/course/grades.py b/course/grades.py index f19cab12..012a474c 100644 --- a/course/grades.py +++ b/course/grades.py @@ -27,6 +27,8 @@ THE SOFTWARE. import re import six +from typing import cast + from django.utils.translation import ( ugettext_lazy as _, pgettext_lazy, ugettext, string_concat) from django.shortcuts import ( # noqa @@ -59,10 +61,11 @@ from course.constants import ( # {{{ for mypy -from typing import cast, Tuple, Text, Optional, Any, Iterable, List # noqa -from course.utils import CoursePageContext # noqa -from course.content import FlowDesc # noqa -from course.models import Course, FlowPageVisitGrade # noqa +if False: + from typing import Tuple, Text, Optional, Any, Iterable, List # noqa + from course.utils import CoursePageContext # noqa + from course.content import FlowDesc # noqa + from course.models import Course, FlowPageVisitGrade # noqa # }}} diff --git a/course/grading.py b/course/grading.py index ca0c2ab9..d8e58a77 100644 --- a/course/grading.py +++ b/course/grading.py @@ -55,12 +55,13 @@ from course.constants import ( # {{{ for mypy -from typing import Text, Any, Optional, Dict # noqa -from course.models import ( # noqa - GradingOpportunity) -from course.utils import ( # noqa - CoursePageContext) -import datetime # noqa +if False: + from typing import Text, Any, Optional, Dict # noqa + from course.models import ( # noqa + GradingOpportunity) + from course.utils import ( # noqa + CoursePageContext) + import datetime # noqa # }}} diff --git a/course/im.py b/course/im.py index 1deac9c9..d9ffcf3c 100644 --- a/course/im.py +++ b/course/im.py @@ -46,7 +46,8 @@ import sleekxmpp import threading -from typing import List, Dict # noqa +if False: + from typing import List, Dict # noqa # {{{ instant message diff --git a/course/models.py b/course/models.py index 2fc56275..6b4c0f32 100644 --- a/course/models.py +++ b/course/models.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, Any, Optional, Text, Iterable # noqa +from typing import cast import six @@ -59,8 +59,8 @@ from course.page.base import AnswerFeedback # {{{ mypy -from typing import List, Dict # noqa if False: + from typing import List, Dict, Any, Optional, Text, Iterable # noqa # noqa from course.content import FlowDesc # noqa # }}} diff --git a/course/page/base.py b/course/page/base.py index fd82cf5d..3704ba05 100644 --- a/course/page/base.py +++ b/course/page/base.py @@ -44,10 +44,9 @@ from django.conf import settings # {{{ mypy -from typing import Text, Optional, Any, Tuple, Dict, Callable # noqa -from django import http # noqa - if False: + from typing import Text, Optional, Any, Tuple, Dict, Callable # noqa + from django import http # noqa from course.models import ( # noqa Course, FlowSession diff --git a/course/receivers.py b/course/receivers.py index a8b91fb3..b5ad5c0e 100644 --- a/course/receivers.py +++ b/course/receivers.py @@ -34,7 +34,8 @@ from course.models import ( ParticipationPreapproval, ) -from typing import List, Union, Text, Optional, Tuple, Any # noqa +if False: + from typing import List, Union, Text, Optional, Tuple, Any # noqa # {{{ Update enrollment status when a User/Course instance is saved diff --git a/course/sandbox.py b/course/sandbox.py index dc64a4bd..2cdb0744 100644 --- a/course/sandbox.py +++ b/course/sandbox.py @@ -24,6 +24,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ +from typing import cast + import django.forms as forms from django.utils.safestring import mark_safe from django.contrib import messages # noqa @@ -43,7 +45,8 @@ from course.content import FlowPageDesc # {{{ for mypy -from typing import Tuple, Text, Optional, Any, Iterable, Dict, cast # noqa +if False: + from typing import Tuple, Text, Optional, Any, Iterable, Dict # noqa # }}} diff --git a/course/validation.py b/course/validation.py index 06928c33..f3b51b1c 100644 --- a/course/validation.py +++ b/course/validation.py @@ -43,8 +43,8 @@ from relate.utils import Struct # {{{ mypy -from typing import Any, Tuple, Optional, Text, List # noqa if False: + from typing import Any, Tuple, Optional, Text, List # noqa from relate.utils import Repo_ish # noqa from course.models import Course # noqa diff --git a/course/versioning.py b/course/versioning.py index 3e718cc5..079e0c3e 100644 --- a/course/versioning.py +++ b/course/versioning.py @@ -66,9 +66,10 @@ from course.constants import ( # {{{ for mypy -from django import http # noqa -from typing import Tuple, List, Text, Any, Dict # noqa -from dulwich.client import GitClient # noqa +if False: + from django import http # noqa + from typing import Tuple, List, Text, Any, Dict # noqa + from dulwich.client import GitClient # noqa # }}} diff --git a/course/views.py b/course/views.py index 5df27ae0..6f1f14cd 100644 --- a/course/views.py +++ b/course/views.py @@ -83,13 +83,14 @@ from course.utils import ( # noqa # {{{ for mypy -from typing import Tuple, List, Text, Optional, Any, Iterable, Dict # noqa +if False: + from typing import Tuple, List, Text, Optional, Any, Iterable, Dict # noqa -from course.content import ( # noqa - FlowDesc, - ) + from course.content import ( # noqa + FlowDesc, + ) -from accounts.models import User # noqa + from accounts.models import User # noqa # }}} diff --git a/relate/utils.py b/relate/utils.py index 5beecdac..1c93bd93 100644 --- a/relate/utils.py +++ b/relate/utils.py @@ -26,12 +26,16 @@ THE SOFTWARE. import six -from typing import Text, Union, List, Dict, Tuple, Optional, Any # noqa -import datetime # noqa +import datetime import django.forms as forms import dulwich.repo +from typing import Union + +if False: + from typing import Text, List, Dict, Tuple, Optional, Any # noqa + class StyledForm(forms.Form): def __init__(self, *args, **kwargs): -- GitLab