Skip to content

Commit

Permalink
Compliance with newest mypy version
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthiasValvekens committed Oct 20, 2024
1 parent 4155126 commit 0c5cd7f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 37 deletions.
3 changes: 2 additions & 1 deletion pyhanko/pdf_utils/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def pil_image(img: Image.Image, writer: BasePdfFileWriter):
pdf_name('/DeviceGray') if img.mode == 'L' else pdf_name('/DeviceRGB')
)
if img.mode == 'P':
palette: ImagePalette = img.palette
palette: Optional[ImagePalette] = img.palette
assert palette is not None
palette_arr = palette.palette
if palette.mode != 'RGB': # pragma: nocover
raise NotImplementedError
Expand Down
61 changes: 31 additions & 30 deletions pyhanko/sign/diff_analysis/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,46 @@
'VRI_KEY_PATTERN',
]


# /Type: dictionary type (can always be added if correct)
# /Ff: Form field flags
FORMFIELD_ALWAYS_MODIFIABLE = {'/Ff', '/Type'}

FORMFIELD_ALWAYS_MODIFIABLE = frozenset({'/Ff', '/Type'})

# /AP: appearance dictionary
# /AS: current appearance state
# /V: field value
# /F: (widget) annotation flags
# /DA: default appearance
# /Q: quadding
VALUE_UPDATE_KEYS = FORMFIELD_ALWAYS_MODIFIABLE | {
'/AP',
'/AS',
'/V',
'/F',
'/DA',
'/Q',
}

VALUE_UPDATE_KEYS = FORMFIELD_ALWAYS_MODIFIABLE | frozenset(
{
'/AP',
'/AS',
'/V',
'/F',
'/DA',
'/Q',
}
)

VRI_KEY_PATTERN = re.compile('/[A-Z0-9]{40}')


ACROFORM_EXEMPT_STRICT_COMPARISON = {
'/Fields',
'/DR',
'/DA',
'/Q',
'/NeedAppearances',
}


ROOT_EXEMPT_STRICT_COMPARISON = {
'/AcroForm',
'/DSS',
'/Extensions',
'/Metadata',
'/MarkInfo',
'/Version',
}
ACROFORM_EXEMPT_STRICT_COMPARISON = frozenset(
{
'/Fields',
'/DR',
'/DA',
'/Q',
'/NeedAppearances',
}
)

ROOT_EXEMPT_STRICT_COMPARISON = frozenset(
{
'/AcroForm',
'/DSS',
'/Extensions',
'/Metadata',
'/MarkInfo',
'/Version',
}
)
4 changes: 2 additions & 2 deletions pyhanko/sign/diff_analysis/form_rules_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def apply(
def _list_fields(
old_fields: Optional[generic.PdfObject],
new_fields: Optional[generic.PdfObject],
old_path: RawPdfPath,
old_path: Optional[RawPdfPath],
parent_name="",
inherited_ft=None,
) -> Generator[Tuple[str, FieldComparisonSpec], None, None]:
Expand Down Expand Up @@ -313,7 +313,7 @@ def _make_list(lst: Optional[generic.PdfObject], exc):

if not kids and field_type is None:
raise exc(
f"Field type of terminal field {fq_name} could not be "
f"Field type of terminal field {fq_name!r} could not be "
f"determined"
)
yield fq_name, (field_type, field_ref.reference, kids, ix)
Expand Down
2 changes: 1 addition & 1 deletion pyhanko/sign/diff_analysis/rules/form_field_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def __init__(
else FORMFIELD_ALWAYS_MODIFIABLE
)
self.value_update_keys = (
value_update_keys
frozenset(value_update_keys)
if value_update_keys is not None
else VALUE_UPDATE_KEYS
)
Expand Down
10 changes: 7 additions & 3 deletions pyhanko/sign/validation/ades.py
Original file line number Diff line number Diff line change
Expand Up @@ -1798,9 +1798,13 @@ async def _process_signature_ts(
signature_ts_result = AdESBasicValidationResult(
ades_subindic=AdESPassed.OK,
# TODO update pyHanko status object as well
api_status=dataclasses.replace(
signature_ts_prelim_result.api_status,
validation_path=validation_path,
api_status=(
dataclasses.replace(
signature_ts_prelim_result.api_status,
validation_path=validation_path,
)
if signature_ts_prelim_result.api_status
else None
),
failure_msg=None,
validation_objects=signature_ts_prelim_result.validation_objects,
Expand Down

0 comments on commit 0c5cd7f

Please sign in to comment.