Skip to content

Commit

Permalink
Update Runner Python Packages (#1322)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuyuutsu authored Mar 7, 2024
1 parent 9b954f5 commit b1e8d85
Show file tree
Hide file tree
Showing 32 changed files with 2,928 additions and 2,893 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ verify_ssl = true
mock = "*"
pytest-cov = "*"
jsonschema = "*"
pylint = "*"
pylint = "<3.0.0"
pylint-mccabe = "*"
pylint-quotes = "*"
pylint-absolute-imports = "*"
Expand Down
5,495 changes: 2,745 additions & 2,750 deletions Pipfile.lock

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions app/authentication/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@ def load_user(extend_session: bool = True) -> Optional[User]:
user_ik_present=USER_IK in cookie_session,
eq_session_id_present=EQ_SESSION_ID in cookie_session,
session_store_exists=bool(session_store),
session_expiration=session_store.expiration_time.isoformat()
if session_store and session_store.expiration_time
else None,
session_expiration=(
session_store.expiration_time.isoformat()
if session_store and session_store.expiration_time
else None
),
)

cookie_session.pop(USER_IK, None)
Expand Down
19 changes: 9 additions & 10 deletions app/data_models/answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,27 @@ def to_dict(self) -> dict:


@overload
def escape_answer_value(value: ListAnswer) -> ListAnswerEscaped:
... # pragma: no cover
def escape_answer_value(value: ListAnswer) -> ListAnswerEscaped: ... # pragma: no cover


@overload
def escape_answer_value(value: DictAnswer) -> DictAnswerEscaped:
... # pragma: no cover
def escape_answer_value(value: DictAnswer) -> DictAnswerEscaped: ... # pragma: no cover


@overload
def escape_answer_value(value: ListDictAnswer) -> ListDictAnswerEscaped:
... # pragma: no cover
def escape_answer_value(
value: ListDictAnswer,
) -> ListDictAnswerEscaped: ... # pragma: no cover


@overload
def escape_answer_value(value: str) -> Markup:
... # pragma: no cover
def escape_answer_value(value: str) -> Markup: ... # pragma: no cover


@overload
def escape_answer_value(value: Union[None, int, Decimal]) -> Union[None, int, Decimal]:
... # pragma: no cover
def escape_answer_value(
value: Union[None, int, Decimal]
) -> Union[None, int, Decimal]: ... # pragma: no cover


def escape_answer_value(
Expand Down
6 changes: 2 additions & 4 deletions app/data_models/list_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ def __iter__(self) -> Iterator[str]:
yield from self.items

@overload
def __getitem__(self, list_item_index: int) -> str:
... # pragma: no cover
def __getitem__(self, list_item_index: int) -> str: ... # pragma: no cover

@overload
def __getitem__(self, list_item_index: slice) -> list[str]:
... # pragma: no cover
def __getitem__(self, list_item_index: slice) -> list[str]: ... # pragma: no cover

def __getitem__(self, list_item_index: slice | int) -> str | list[str]:
return self.items[list_item_index]
Expand Down
6 changes: 3 additions & 3 deletions app/forms/field_handlers/field_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ def get_schema_value(
) -> Union[ValueSourceEscapedTypes, ValueSourceTypes]:
if isinstance(schema_element["value"], dict):
return self.value_source_resolver.resolve(schema_element["value"])
schema_element_value: Union[
ValueSourceEscapedTypes, ValueSourceTypes
] = schema_element["value"]
schema_element_value: Union[ValueSourceEscapedTypes, ValueSourceTypes] = (
schema_element["value"]
)
return schema_element_value

def get_field(self) -> Field:
Expand Down
8 changes: 5 additions & 3 deletions app/forms/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,11 @@ def __call__(
raise validators.ValidationError(self.messages["MUTUALLY_EXCLUSIVE"])
if is_mandatory and total_answered < 1:
message = format_message_with_title(
self.messages["MANDATORY_CHECKBOX"]
if is_only_checkboxes_or_radios
else self.messages["MANDATORY_QUESTION"],
(
self.messages["MANDATORY_CHECKBOX"]
if is_only_checkboxes_or_radios
else self.messages["MANDATORY_QUESTION"]
),
self.question_title,
)
raise validators.ValidationError(message)
Expand Down
3 changes: 2 additions & 1 deletion app/helpers/url_safe_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@


def url_safe_serializer() -> URLSafeSerializer:
return URLSafeSerializer(current_app.secret_key, salt=cookie_session[EQ_SESSION_ID])
# Type Ignore: Secret key is validated on app start up, so it must exist at this point
return URLSafeSerializer(current_app.secret_key, salt=cookie_session[EQ_SESSION_ID]) # type: ignore
10 changes: 4 additions & 6 deletions app/jinja_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,10 @@ def get_format_date_range(start_date: Markup, end_date: Markup) -> Markup:


@blueprint.app_context_processor
def format_unit_processor() -> (
dict[
str,
Callable[[str, int | float | Decimal, UnitLengthType], str],
]
):
def format_unit_processor() -> dict[
str,
Callable[[str, int | float | Decimal, UnitLengthType], str],
]:
return {"format_unit": format_unit}


Expand Down
4 changes: 3 additions & 1 deletion app/questionnaire/placeholder_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ def _parse_transforms(
transform_args["unresolved_arguments"] = transform["arguments"]

for arg_key, arg_value in transform["arguments"].items():
resolved_value: ValueSourceEscapedTypes | ValueSourceTypes | TransformedValueTypes
resolved_value: (
ValueSourceEscapedTypes | ValueSourceTypes | TransformedValueTypes
)

if isinstance(arg_value, list):
resolved_value = value_source_resolver.resolve_list(
Expand Down
36 changes: 18 additions & 18 deletions app/questionnaire/questionnaire_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,33 +84,33 @@ def __init__(
self, questionnaire_json: Mapping, language_code: str = DEFAULT_LANGUAGE_CODE
):
self._parent_id_map: dict[str, str] = {}
self._list_collector_section_ids_by_list_name: dict[
str, list[str]
] = defaultdict(list)
self._list_collector_section_ids_by_list_name: dict[str, list[str]] = (
defaultdict(list)
)
self._answer_dependencies_map: dict[str, set[Dependent]] = defaultdict(set)
self._list_dependencies_map: dict[str, set[Dependent]] = defaultdict(set)
self._when_rules_section_dependencies_by_section: dict[
str, set[str]
] = defaultdict(set)
self._when_rules_section_dependencies_by_section_for_progress_value_source: defaultdict[
str, OrderedSet[str]
] = defaultdict(
self._when_rules_section_dependencies_by_section: dict[str, set[str]] = (
defaultdict(set)
)
self._when_rules_section_dependencies_by_section_for_progress_value_source: (
defaultdict[str, OrderedSet[str]]
) = defaultdict(
OrderedSet
)
self._when_rules_block_dependencies_by_section_for_progress_value_source: defaultdict[
str, DependencyDictType
] = defaultdict(
self._when_rules_block_dependencies_by_section_for_progress_value_source: (
defaultdict[str, DependencyDictType]
) = defaultdict(
lambda: defaultdict(OrderedSet)
)
self.calculation_summary_section_dependencies_by_block: dict[
str, DependencyDictType
] = defaultdict(lambda: defaultdict(OrderedSet))
self._when_rules_section_dependencies_by_answer: dict[
str, set[str]
] = defaultdict(set)
self._when_rules_section_dependencies_by_list: dict[
str, set[str]
] = defaultdict(set)
self._when_rules_section_dependencies_by_answer: dict[str, set[str]] = (
defaultdict(set)
)
self._when_rules_section_dependencies_by_list: dict[str, set[str]] = (
defaultdict(set)
)
self._placeholder_transform_section_dependencies_by_block: dict[
str, dict[str, set[str]]
] = defaultdict(lambda: defaultdict(set))
Expand Down
28 changes: 17 additions & 11 deletions app/questionnaire/questionnaire_store_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def __init__(
self._progress_store = self._questionnaire_store.data_stores.progress_store
self._router = router

self.dependent_block_id_by_section_key: Mapping[
SectionKey, set[str]
] = defaultdict(set)
self.dependent_block_id_by_section_key: Mapping[SectionKey, set[str]] = (
defaultdict(set)
)
self.dependent_sections: set[DependentSection] = set()

@property
Expand Down Expand Up @@ -342,8 +342,10 @@ def _capture_section_dependencies_progress_value_source_for_section(
"""
Captures a unique list of section ids that are dependents of the provided section, for progress value sources.
"""
dependent_sections: Iterable = self._schema.when_rules_section_dependencies_by_section_for_progress_value_source.get(
section_id, set()
dependent_sections: Iterable = (
self._schema.when_rules_section_dependencies_by_section_for_progress_value_source.get(
section_id, set()
)
)
self._update_section_dependencies(dependent_sections)

Expand All @@ -353,10 +355,12 @@ def _capture_section_dependencies_progress_value_source_for_block(
"""
Captures a unique list of section ids that are dependents of the provided block, for progress value sources.
"""
dependent_sections: Iterable = self._schema.when_rules_block_dependencies_by_section_for_progress_value_source.get(
section_id, {}
).get(
block_id, set()
dependent_sections: Iterable = (
self._schema.when_rules_block_dependencies_by_section_for_progress_value_source.get(
section_id, {}
).get(
block_id, set()
)
)
self._update_section_dependencies(dependent_sections)

Expand Down Expand Up @@ -411,8 +415,10 @@ def _evaluate_dependents(
if self.update_section_status(
is_complete=is_path_complete, section_key=dependent_section.section_key
):
dependents_of_dependent: OrderedSet = self._schema.when_rules_section_dependencies_by_section_for_progress_value_source.get(
dependent_section.section_id, OrderedSet()
dependents_of_dependent: OrderedSet = (
self._schema.when_rules_section_dependencies_by_section_for_progress_value_source.get(
dependent_section.section_id, OrderedSet()
)
)
for dependent_section_id in dependents_of_dependent:
if repeating_list := self._schema.get_repeating_list_for_section(
Expand Down
1 change: 1 addition & 0 deletions app/questionnaire/rules/operations_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
The methods here invoke operations methods, so it can be imported in placeholder transformer
this is a temporary solution until placeholder transformer is refactored.
"""

from datetime import date
from typing import TYPE_CHECKING, Optional

Expand Down
6 changes: 2 additions & 4 deletions app/questionnaire/rules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ def parse_iso_8601_datetime(iso_8601_date_string: str) -> datetime:


@overload
def parse_datetime(date_string: None) -> None:
... # pragma: no cover
def parse_datetime(date_string: None) -> None: ... # pragma: no cover


@overload
def parse_datetime(date_string: str) -> datetime:
... # pragma: no cover
def parse_datetime(date_string: str) -> datetime: ... # pragma: no cover


def parse_datetime(date_string: Optional[str]) -> Optional[datetime]:
Expand Down
8 changes: 5 additions & 3 deletions app/questionnaire/value_source_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,11 @@ def _resolve_progress_value_source(
block_id=identifier,
section_key=SectionKey(
section_id=section_id_for_block,
list_item_id=self.location.list_item_id
if self.location.section_id == section_id_for_block
else None,
list_item_id=(
self.location.list_item_id
if self.location.section_id == section_id_for_block
else None
),
),
)

Expand Down
15 changes: 8 additions & 7 deletions app/routes/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@ def bad_request(
@errors_blueprint.app_errorhandler(NoQuestionnaireStateException)
@errors_blueprint.app_errorhandler(Unauthorized)
def unauthorized(
exception: CSRFError
| NoTokenException
| NoQuestionnaireStateException
| Unauthorized,
exception: (
CSRFError | NoTokenException | NoQuestionnaireStateException | Unauthorized
),
) -> tuple[str, int]:
log_exception(exception, 401)
return _render_error_page(401, template="401")
Expand Down Expand Up @@ -198,9 +197,11 @@ def too_many_feedback_requests(
@errors_blueprint.app_errorhandler(MissingSupplementaryDataKey)
@errors_blueprint.app_errorhandler(InvalidSupplementaryData)
def supplementary_data_request_failed(
exception: SupplementaryDataRequestFailed
| MissingSupplementaryDataKey
| InvalidSupplementaryData,
exception: (
SupplementaryDataRequestFailed
| MissingSupplementaryDataKey
| InvalidSupplementaryData
),
) -> tuple[str, int]:
log_exception(exception, 500)
return _render_error_page(500, template=500)
Expand Down
7 changes: 4 additions & 3 deletions app/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,10 @@ def add_blueprints(application):


def setup_secure_cookies(application):
application.secret_key = application.eq["secret_store"].get_secret_by_name(
"EQ_SECRET_KEY"
)
secret_key = application.eq["secret_store"].get_secret_by_name("EQ_SECRET_KEY")
if not secret_key:
raise ValueError("Application secret key does not exist")
application.secret_key = secret_key
application.session_interface = SHA256SecureCookieSessionInterface()


Expand Down
6 changes: 3 additions & 3 deletions app/storage/dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def put(self, model: ModelTypes, overwrite: bool = True) -> bool:

put_kwargs: dict = {"Item": storage_model.serialize(model)}
if not overwrite:
put_kwargs[
"ConditionExpression"
] = f"attribute_not_exists({storage_model.key_field})"
put_kwargs["ConditionExpression"] = (
f"attribute_not_exists({storage_model.key_field})"
)

try:
response = table.put_item(**put_kwargs)["ResponseMetadata"][
Expand Down
Loading

0 comments on commit b1e8d85

Please sign in to comment.