• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

p2p-ld / numpydantic / 27054202885

06 Jun 2026 05:49AM UTC coverage: 97.114% (-0.7%) from 97.821%
27054202885

Pull #69

github

web-flow
Merge c1c4272d0 into 952a740e0
Pull Request #69: aw shit it's mypy plugin time

376 of 403 new or added lines in 14 files covered. (93.3%)

4 existing lines in 1 file now uncovered.

1918 of 1975 relevant lines covered (97.11%)

6.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.91
/src/numpydantic/interface/typing.py
1
"""
2
Per-interface static-typing for the mypy plugin
3

4
A backend interface may attach an :class:`InterfaceTyping` subclass to its
5
:attr:`Interface.typing` class variable to opt into:
6

7
- Mypy plugin constructor inference (so ``da.zeros((3, 3), dtype=np.uint8)``
8
  refines to a literal-tuple shape and concrete dtype in the same way numpy
9
  constructors do).
10
- Mypy test file generation (the test generator uses the typing class to
11
  emit literal constructor expressions for each combinatorial test case).
12
"""
13

14
from __future__ import annotations
7✔
15

16
from dataclasses import dataclass
7✔
17
from typing import ClassVar, Literal
7✔
18

19

20
@dataclass(frozen=True)
7✔
21
class ConstructorSpec:
7✔
22
    """
23
    How a single array-constructor call exposes shape and dtype.
24
    """
25

26
    fullname: str
7✔
27
    """
7✔
28
    Mypy-visible fully qualified name of the function or method,
29
    e.g. ``"dask.array.zeros"`` or
30
    ``"numpy._core.multiarray._ConstructorEmpty.__call__"``.
31
    """
32
    shape_arg: int | str = 0
7✔
33
    """
7✔
34
    Where the shape argument lives in the call. 
35
    An ``int`` is a positional index; 
36
    a ``str`` is a keyword name.
37
    """
38
    dtype_arg: str | None = "dtype"
7✔
39
    """Keyword name for the dtype argument, if any"""
7✔
40
    mode: Literal["function", "method"] = "function"
7✔
41
    """
7✔
42
    ``method`` if mypy sees this constructor as a method (``get_method_hook``), 
43
    ``function`` for a free function or class instantiation (``get_function_hook``).
44
    """
45

46

47
class InterfaceTyping:
7✔
48
    """
49
    Optional static-typing companion class for an :class:`Interface`,
50
    for use with the mypy plugin.
51
    """
52

53
    constructors: ClassVar[tuple[ConstructorSpec, ...]] = ()
7✔
54
    """Constructor calls whose return type the mypy plugin should refine."""
7✔
55

56
    @classmethod
7✔
57
    def emit_imports(cls) -> list[str]:
7✔
58
        """Import lines required by :meth:`emit_constructor_source`.
59

60
        Returned as a list of statement strings, e.g.
61
        ``["import numpy as np", "import dask.array as da"]``.
62
        """
NEW
63
        return []
×
64

65
    @classmethod
7✔
66
    def emit_constructor_source(cls, shape: tuple[int, ...], dtype: str) -> str | None:
7✔
67
        """Source-text for a constructor call producing the given array.
68

69
        Returns a Python expression string (no trailing newline), e.g.
70
        ``"np.zeros((3, 3), dtype=np.uint8)"``.
71

72
        Only needs to render one of the constructors that the interface supports -
73
        we assume if we detect one, they should all work the same way.
74
        """
NEW
75
        return None
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc