From 3d7d64f4a1f446acb00b183b7877e5c0c8458fd5 Mon Sep 17 00:00:00 2001 From: Carl Beekhuizen Date: Sat, 9 May 2020 03:36:33 +0200 Subject: [PATCH] Fixes Typing errors for points at infinity (NoneTypes) (#89) * Fixes Typing errors for points at infinity (NoneTypes) * type: ignore -> type: ignore[misc] * Adds @hwwhww's mypy fixes. * Apply @hwwhww's suggestion [] -> () Co-authored-by: Hsiao-Wei Wang Co-authored-by: Hsiao-Wei Wang --- py_ecc/fields/field_elements.py | 2 +- py_ecc/fields/optimized_field_elements.py | 2 +- py_ecc/typing.py | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/py_ecc/fields/field_elements.py b/py_ecc/fields/field_elements.py index 87d8c3b0..41d87b63 100644 --- a/py_ecc/fields/field_elements.py +++ b/py_ecc/fields/field_elements.py @@ -201,7 +201,7 @@ class FQP(object): def __init__(self, coeffs: Sequence[IntOrFQ], - modulus_coeffs: Sequence[IntOrFQ] = None) -> None: + modulus_coeffs: Sequence[IntOrFQ] = ()) -> None: if self.field_modulus is None: raise AttributeError("Field Modulus hasn't been specified") diff --git a/py_ecc/fields/optimized_field_elements.py b/py_ecc/fields/optimized_field_elements.py index 23207e82..cc654441 100644 --- a/py_ecc/fields/optimized_field_elements.py +++ b/py_ecc/fields/optimized_field_elements.py @@ -216,7 +216,7 @@ class FQP(object): def __init__(self, coeffs: Sequence[IntOrFQ], - modulus_coeffs: Sequence[IntOrFQ] = None) -> None: + modulus_coeffs: Sequence[IntOrFQ] = ()) -> None: if self.field_modulus is None: raise AttributeError("Field Modulus hasn't been specified") diff --git a/py_ecc/typing.py b/py_ecc/typing.py index f4c9b911..da9e9d1f 100644 --- a/py_ecc/typing.py +++ b/py_ecc/typing.py @@ -1,4 +1,5 @@ from typing import ( + Optional, Tuple, TypeVar, Union, @@ -64,8 +65,8 @@ bls12_381_FQ2, bls12_381_FQ12, ) -Point2D = Tuple[Field, Field] -Point3D = Tuple[Field, Field, Field] +Point2D = Optional[Tuple[Field, Field]] # Point at infinity is encoded as a None +Point3D = Optional[Tuple[Field, Field, Field]] # Point at infinity is encoded as a None GeneralPoint = Union[Point2D[Field], Point3D[Field]]