Skip to content

Commit d5f1a12

Browse files
committed
typ: fix mpoly_p typing protocol
1 parent 6d164a1 commit d5f1a12

File tree

7 files changed

+129
-39
lines changed

7 files changed

+129
-39
lines changed

src/flint/flint_base/flint_base.pyi

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ class flint_scalar(flint_elem):
3636
def is_zero(self) -> bool: ...
3737
def __pos__(self) -> Self: ...
3838
def __neg__(self) -> Self: ...
39-
def __add__(self, other: int, /) -> Self: ...
39+
def __add__(self, other: Self | int, /) -> Self: ...
4040
def __radd__(self, other: int, /) -> Self: ...
41-
def __sub__(self, other: int, /) -> Self: ...
41+
def __sub__(self, other: Self | int, /) -> Self: ...
4242
def __rsub__(self, other: int, /) -> Self: ...
43-
def __mul__(self, other: int, /) -> Self: ...
43+
def __mul__(self, other: Self | int, /) -> Self: ...
4444
def __rmul__(self, other: int, /) -> Self: ...
45-
def __truediv__(self, other: int, /) -> Self: ...
45+
def __truediv__(self, other: Self | int, /) -> Self: ...
4646
def __rtruediv__(self, other: int, /) -> Self: ...
4747
def __pow__(self, other: int, /) -> Self: ...
4848
def __rpow__(self, other: int, /) -> Self: ...
@@ -193,14 +193,14 @@ class flint_mpoly_context(flint_elem, Generic[Tmpoly, Telem, Telem_coerce]):
193193
@classmethod
194194
def from_context(
195195
cls,
196-
ctx: Sctx,
196+
ctx: flint_mpoly_context,
197197
names: str | Iterable[str | tuple[str, int]] | tuple[str, int] | None = None,
198198
ordering: Ordering | str = Ordering.lex,
199-
) -> Sctx: ...
199+
) -> Self: ...
200200

201201
class flint_mod_mpoly_context(flint_mpoly_context[Tmpoly, Telem, Telem_coerce]):
202202
@abstractmethod
203-
def modulus(self) -> int: ...
203+
def modulus(self): ...
204204

205205
class flint_series(flint_elem, Generic[Telem]):
206206
"""Base class for power series."""

src/flint/test/test_all.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ def raises(f, exception) -> bool:
3232
Tscalar = TypeVar('Tscalar', bound=flint_base.flint_scalar)
3333
Tscalar_co = TypeVar('Tscalar_co', bound=flint_base.flint_scalar, covariant=True)
3434
Tmpoly = TypeVar('Tmpoly', bound=flint_base.flint_mpoly)
35+
Tmpoly_p = TypeVar('Tmpoly_p', bound=typ.mpoly_p)
3536
Tmpolyctx_co = TypeVar('Tmpolyctx_co', bound=flint_base.flint_mpoly_context, covariant=True)
37+
Tmpolyctx_p_co = TypeVar('Tmpolyctx_p_co', bound=typ.mpoly_context_p, covariant=True)
3638

3739

3840
_default_ctx_string = """\
@@ -3093,17 +3095,17 @@ def _all_mpolys(): # -> _all_mpolys_type:
30933095
)
30943096

30953097

3096-
class _GetMPolyCtx(Protocol[Tmpolyctx_co]):
3098+
class _GetMPolyCtx(Protocol[Tmpolyctx_p_co]):
30973099
def __call__(self,
30983100
names: Iterable[str | tuple[str, int]] | tuple[str, int],
30993101
ordering: str | flint.Ordering = "lex"
3100-
) -> Tmpolyctx_co:
3102+
) -> Tmpolyctx_p_co:
31013103
...
31023104

31033105

31043106
_MPolyTestCase = tuple[
3105-
type[Tmpoly],
3106-
_GetMPolyCtx['flint_base.flint_mpoly_context[Tmpoly, Tscalar, int]'],
3107+
type[Tmpoly_p],
3108+
_GetMPolyCtx[typ.mpoly_context_p[Tmpoly_p, Tscalar]],
31073109
Callable[[int], Tscalar],
31083110
bool,
31093111
flint.fmpz
@@ -3176,7 +3178,7 @@ def wrapper():
31763178

31773179

31783180
@all_mpolys
3179-
def test_mpolys_constructor(args: _MPolyTestCase[Tmpoly, Tscalar]) -> None:
3181+
def test_mpolys_constructor(args: _MPolyTestCase[Tmpoly_p, Tscalar]) -> None:
31803182
P, get_context, S, _, _ = args
31813183

31823184
ctx = get_context(("x", 2))
@@ -3301,7 +3303,7 @@ def quick_poly():
33013303

33023304

33033305
@all_mpolys
3304-
def test_mpolys_properties(args: _MPolyTestCase[Tmpoly, Tscalar]) -> None:
3306+
def test_mpolys_properties(args: _MPolyTestCase[Tmpoly_p, Tscalar]) -> None:
33053307

33063308
P, get_context, S, is_field, characteristic = args
33073309

src/flint/types/fmpq_mpoly.pyi

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Iterable, Mapping
1+
from typing import Iterable, Mapping, Any
22
from ..flint_base.flint_base import flint_mpoly, flint_mpoly_context, Ordering
33
from .fmpz import fmpz
44
from .fmpq import fmpq
@@ -20,11 +20,28 @@ class fmpq_mpoly_ctx(flint_mpoly_context[fmpq_mpoly, fmpq, ifmpq]):
2020

2121
def nvars(self) -> int: ...
2222
def ordering(self) -> Ordering: ...
23-
24-
def gen(self, i: int) -> fmpq_mpoly: ...
25-
def from_dict(self, d: Mapping[tuple[int, ...], ifmpq]) -> fmpq_mpoly: ...
26-
def constant(self, z: ifmpq) -> fmpq_mpoly: ...
27-
23+
def gen(self, i: int, /) -> fmpq_mpoly: ...
24+
def from_dict(self, d: Mapping[tuple[int, ...], ifmpq], /) -> fmpq_mpoly: ...
25+
def constant(self, q: ifmpq, /) -> fmpq_mpoly: ...
26+
def name(self, i: int, /) -> str: ...
27+
def names(self) -> tuple[str]: ...
28+
def gens(self) -> tuple[fmpq_mpoly, ...]: ...
29+
def variable_to_index(self, var: str, /) -> int: ...
30+
def term(
31+
self, coeff: ifmpq | None = None, exp_vec: Iterable[int] | None = None
32+
) -> fmpq_mpoly: ...
33+
def drop_gens(self, gens: Iterable[str | int], /) -> fmpq_mpoly_ctx: ...
34+
def append_gens(self, gens: Iterable[str | int], /) -> fmpq_mpoly_ctx: ...
35+
def infer_generator_mapping(
36+
self, ctx: flint_mpoly_context, /
37+
) -> dict[int, int]: ...
38+
@classmethod
39+
def from_context(
40+
cls,
41+
ctx: flint_mpoly_context[Any, Any, Any],
42+
names: str | Iterable[str | tuple[str, int]] | tuple[str, int] | None = None,
43+
ordering: Ordering | str = Ordering.lex,
44+
) -> fmpq_mpoly_ctx: ...
2845

2946
class fmpq_mpoly(flint_mpoly[fmpq_mpoly_ctx, fmpq, ifmpq]):
3047
def __init__(self,

src/flint/types/fmpz_mod_mpoly.pyi

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
from typing import Iterable, Mapping
2-
from ..flint_base.flint_base import flint_mpoly, flint_mod_mpoly_context, Ordering
1+
from typing import Iterable, Mapping, Any
2+
from ..flint_base.flint_base import (
3+
flint_mpoly,
4+
flint_mpoly_context,
5+
flint_mod_mpoly_context,
6+
Ordering,
7+
)
38
from .fmpz import fmpz
49
from .fmpz_mod import fmpz_mod
510
from .fmpz_mpoly import fmpz_mpoly
@@ -17,16 +22,38 @@ class fmpz_mod_mpoly_ctx(flint_mod_mpoly_context[fmpz_mod_mpoly, fmpz_mod, ifmpz
1722
names: _str | Iterable[_str | tuple[_str, int]] | tuple[_str, int],
1823
ordering: Ordering | _str = Ordering.lex,
1924
*,
20-
modulus: ifmpz,
25+
modulus: int,
2126
) -> fmpz_mod_mpoly_ctx:
2227
...
2328

29+
def modulus(self) -> fmpz: ...
30+
2431
def nvars(self) -> int: ...
2532
def ordering(self) -> Ordering: ...
26-
def modulus(self) -> int: ...
27-
def gen(self, i: int, /) -> fmpz_mod_mpoly: ...
28-
def constant(self, z: ifmpz_mod) -> fmpz_mod_mpoly: ...
33+
34+
def gen(self, i: int) -> fmpz_mod_mpoly: ...
2935
def from_dict(self, d: Mapping[tuple[int, ...], ifmpz_mod]) -> fmpz_mod_mpoly: ...
36+
def constant(self, z: ifmpz_mod) -> fmpz_mod_mpoly: ...
37+
38+
def name(self, i: int, /) -> str: ...
39+
def names(self) -> tuple[str]: ...
40+
def gens(self) -> tuple[fmpz_mod_mpoly, ...]: ...
41+
def variable_to_index(self, var: str, /) -> int: ...
42+
def term(
43+
self, coeff: ifmpz_mod | None = None, exp_vec: Iterable[int] | None = None
44+
) -> fmpz_mod_mpoly: ...
45+
def drop_gens(self, gens: Iterable[str | int], /) -> fmpz_mod_mpoly_ctx: ...
46+
def append_gens(self, gens: Iterable[str | int], /) -> fmpz_mod_mpoly_ctx: ...
47+
def infer_generator_mapping(
48+
self, ctx: flint_mpoly_context, /
49+
) -> dict[int, int]: ...
50+
@classmethod
51+
def from_context(
52+
cls,
53+
ctx: flint_mpoly_context[Any, Any, Any],
54+
names: str | Iterable[str | tuple[str, int]] | tuple[str, int] | None = None,
55+
ordering: Ordering | str = Ordering.lex,
56+
) -> fmpz_mod_mpoly_ctx: ...
3057

3158

3259
class fmpz_mod_mpoly(flint_mpoly[fmpz_mod_mpoly_ctx, fmpz_mod, ifmpz_mod]):

src/flint/types/fmpz_mpoly.pyi

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Iterable, Iterator, Mapping
1+
from typing import Iterable, Iterator, Mapping, Any
22

33
from ..flint_base.flint_base import flint_mpoly, flint_mpoly_context, Ordering
44
from .fmpz import fmpz
@@ -18,11 +18,28 @@ class fmpz_mpoly_ctx(flint_mpoly_context[fmpz_mpoly, fmpz, ifmpz]):
1818

1919
def nvars(self) -> int: ...
2020
def ordering(self) -> Ordering: ...
21-
22-
def gen(self, i: int) -> fmpz_mpoly: ...
23-
def from_dict(self, d: Mapping[tuple[int, ...], ifmpz]) -> fmpz_mpoly: ...
24-
def constant(self, z: ifmpz) -> fmpz_mpoly: ...
25-
21+
def gen(self, i: int, /) -> fmpz_mpoly: ...
22+
def from_dict(self, d: Mapping[tuple[int, ...], ifmpz], /) -> fmpz_mpoly: ...
23+
def constant(self, z: ifmpz, /) -> fmpz_mpoly: ...
24+
def name(self, i: int, /) -> str: ...
25+
def names(self) -> tuple[str]: ...
26+
def gens(self) -> tuple[fmpz_mpoly, ...]: ...
27+
def variable_to_index(self, var: str, /) -> int: ...
28+
def term(
29+
self, coeff: ifmpz | None = None, exp_vec: Iterable[int] | None = None
30+
) -> fmpz_mpoly: ...
31+
def drop_gens(self, gens: Iterable[str | int], /) -> fmpz_mpoly_ctx: ...
32+
def append_gens(self, gens: Iterable[str | int], /) -> fmpz_mpoly_ctx: ...
33+
def infer_generator_mapping(
34+
self, ctx: flint_mpoly_context, /
35+
) -> dict[int, int]: ...
36+
@classmethod
37+
def from_context(
38+
cls,
39+
ctx: flint_mpoly_context[Any, Any, Any],
40+
names: str | Iterable[str | tuple[str, int]] | tuple[str, int] | None = None,
41+
ordering: Ordering | str = Ordering.lex,
42+
) -> fmpz_mpoly_ctx: ...
2643

2744
class fmpz_mpoly(flint_mpoly[fmpz_mpoly_ctx, fmpz, ifmpz]):
2845

src/flint/types/nmod_mpoly.pyi

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
from typing import Iterable, Mapping, Self
2-
from ..flint_base.flint_base import flint_mpoly, flint_mpoly_context, Ordering
1+
from typing import Iterable, Mapping, Self, Any
2+
from ..flint_base.flint_base import (
3+
flint_mpoly,
4+
flint_mpoly_context,
5+
flint_mod_mpoly_context,
6+
Ordering,
7+
)
38
from .fmpz import fmpz
49
from .fmpq import fmpq
510
from .nmod import nmod
@@ -11,7 +16,7 @@ ifmpz = int | fmpz
1116
inmod = int | fmpz | fmpq | nmod
1217

1318

14-
class nmod_mpoly_ctx(flint_mpoly_context[nmod_mpoly, nmod, inmod]):
19+
class nmod_mpoly_ctx(flint_mod_mpoly_context[nmod_mpoly, nmod, inmod]):
1520

1621
@classmethod
1722
def get(cls,
@@ -22,13 +27,35 @@ class nmod_mpoly_ctx(flint_mpoly_context[nmod_mpoly, nmod, inmod]):
2227
) -> nmod_mpoly_ctx:
2328
...
2429

30+
def modulus(self) -> int: ...
31+
2532
def nvars(self) -> int: ...
2633
def ordering(self) -> Ordering: ...
2734

2835
def gen(self, i: int) -> nmod_mpoly: ...
2936
def from_dict(self, d: Mapping[tuple[int, ...], inmod]) -> nmod_mpoly: ...
3037
def constant(self, z: inmod) -> nmod_mpoly: ...
3138

39+
def name(self, i: int, /) -> str: ...
40+
def names(self) -> tuple[str]: ...
41+
def gens(self) -> tuple[nmod_mpoly, ...]: ...
42+
def variable_to_index(self, var: str, /) -> int: ...
43+
def term(
44+
self, coeff: inmod | None = None, exp_vec: Iterable[int] | None = None
45+
) -> nmod_mpoly: ...
46+
def drop_gens(self, gens: Iterable[str | int], /) -> nmod_mpoly_ctx: ...
47+
def append_gens(self, gens: Iterable[str | int], /) -> nmod_mpoly_ctx: ...
48+
def infer_generator_mapping(
49+
self, ctx: flint_mpoly_context, /
50+
) -> dict[int, int]: ...
51+
@classmethod
52+
def from_context(
53+
cls,
54+
ctx: flint_mpoly_context[Any, Any, Any],
55+
names: str | Iterable[str | tuple[str, int]] | tuple[str, int] | None = None,
56+
ordering: Ordering | str = Ordering.lex,
57+
) -> nmod_mpoly_ctx: ...
58+
3259

3360
class nmod_mpoly(flint_mpoly[nmod_mpoly_ctx, nmod, inmod]):
3461
def __init__(self,

src/flint/typing.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ class mpoly_context_p(elem_p, Protocol[_Tmpoly_p, _Telem_contra]):
234234
def nvars(self) -> int: ...
235235
def ordering(self) -> Ordering: ...
236236
def gen(self, i: int, /) -> _Tmpoly_p: ...
237-
def from_dict(self, d: Mapping[tuple[int, ...], _Telem_contra], /) -> _Tmpoly_p: ...
238-
def constant(self, z: _Telem_contra, /) -> _Tmpoly_p: ...
237+
def from_dict(self, d: Mapping[tuple[int, ...], _Telem_contra | int], /) -> _Tmpoly_p: ...
238+
def constant(self, z: _Telem_contra | int, /) -> _Tmpoly_p: ...
239239
def name(self, i: int, /) -> str: ...
240240
def names(self) -> tuple[str]: ...
241241
def gens(self) -> tuple[_Tmpoly_p, ...]: ...
@@ -246,15 +246,15 @@ def term(
246246
def drop_gens(self, gens: Iterable[str | int], /) -> Self: ...
247247
def append_gens(self, gens: Iterable[str | int], /) -> Self: ...
248248
def infer_generator_mapping(
249-
self, ctx: flint_mpoly_context, /
249+
self, ctx: Self, /
250250
) -> dict[int, int]: ...
251251
@classmethod
252252
def from_context(
253253
cls,
254-
ctx: _Sctx,
254+
ctx: flint_mpoly_context,
255255
names: str | Iterable[str | tuple[str, int]] | tuple[str, int] | None = None,
256256
ordering: Ordering | str = Ordering.lex,
257-
) -> _Sctx: ...
257+
) -> Self: ...
258258

259259

260260
if TYPE_CHECKING:

0 commit comments

Comments
 (0)