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

rjfarmer / gfModParser / 18258850406

05 Oct 2025 12:39PM UTC coverage: 89.798% (-0.08%) from 89.88%
18258850406

push

github

rjfarmer
Fix type annotations

1 of 2 new or added lines in 1 file covered. (50.0%)

977 of 1088 relevant lines covered (89.8%)

0.9 hits per line

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

85.54
/gfModParser/modules/arrays.py
1
# SPDX-License-Identifier: GPL-2.0+
2

3
import numpy as np
1✔
4

5
from . import expressions
1✔
6

7

8
class arrayspec:
1✔
9
    def __init__(self, array, *, version):
1✔
10
        self._array = array
1✔
11
        self.version = version
1✔
12

13
        self._low = []
1✔
14
        self._up = []
1✔
15

16
    def __bool__(self):
1✔
17
        return self.is_array
1✔
18

19
    @property
1✔
20
    def is_array(self) -> bool:
1✔
21
        return len(self._array) > 0
1✔
22

23
    @property
1✔
24
    def ndims(self) -> int:
1✔
25
        if self.is_array:
1✔
26
            return self.rank
1✔
27
        return -1
×
28

29
    @property
1✔
30
    def rank(self) -> int:
1✔
31
        if self.is_array:
1✔
32
            return int(self._array[0])
1✔
33
        return -1
×
34

35
    @property
1✔
36
    def corank(self) -> int:
1✔
37
        if self.is_array:
1✔
38
            return int(self._array[1])
1✔
39
        return -1
×
40

41
    @property
1✔
42
    def type(self) -> str:
1✔
43
        if self.is_array:
1✔
44
            return self._array[2]
1✔
NEW
45
        return ""
×
46

47
    @property
1✔
48
    def is_deferred(self) -> bool:
1✔
49
        """
50
        Deferred arrays (like allocatable) do not have compile time bounds, but do have
51
        compile time rank
52
        """
53
        if self.is_array:
1✔
54
            return self.type == "DEFERRED"
1✔
55
        return False
×
56

57
    @property
1✔
58
    def is_explicit(self) -> bool:
1✔
59
        if self.is_array:
×
60
            return self.type == "EXPLICIT"
×
61
        return False
×
62

63
    @property
1✔
64
    def lower(self) -> tuple:
1✔
65
        if self.is_array:
1✔
66
            if len(self._low) == 0:
1✔
67
                for i in range(self.rank + self.corank):
1✔
68
                    if len(self._array[3 + i * 2]):
1✔
69
                        self._low.append(
1✔
70
                            expressions.Expression(
71
                                self._array[3 + i * 2], version=self.version
72
                            )
73
                        )
74

75
            return tuple(self._low)
1✔
76
        return ()
×
77

78
    @property
1✔
79
    def upper(self) -> tuple:
1✔
80
        if self.is_array:
1✔
81
            if len(self._up) == 0:
1✔
82
                for i in range(self.rank + self.corank):
1✔
83
                    if len(self._array[4 + i * 2]):
1✔
84
                        self._up.append(
1✔
85
                            expressions.Expression(
86
                                self._array[4 + i * 2], version=self.version
87
                            )
88
                        )
89

90
            return tuple(self._up)
1✔
91
        return ()
×
92

93
    @property
1✔
94
    def fshape(self) -> tuple:
1✔
95
        """
96
        Returns the array shape as a tuple of Fortran bounds ((lower, upper),..)
97
        """
98
        if self.is_array:
1✔
99
            res = []
1✔
100
            for l, u in zip(self.lower, self.upper):
1✔
101
                res.append((l.value, u.value))
1✔
102

103
            return tuple(res)
1✔
104
        return ()
×
105

106
    @property
1✔
107
    def pyshape(self) -> tuple:
1✔
108
        """
109
        Returns the array shape as a tuple of Python bounds (ndim1,ndim2,..)
110
        """
111
        if self.is_array:
1✔
112
            res = []
1✔
113
            for l, u in zip(self.lower, self.upper):
1✔
114
                res.append(u.value - l.value + 1)
1✔
115

116
            return tuple(res)
1✔
117
        return ()
×
118

119
    @property
1✔
120
    def size(self) -> int:
1✔
121
        if self.is_array:
1✔
122
            if not self.is_deferred:
1✔
123
                return np.prod(self.pyshape)
1✔
124

125
        return -1
1✔
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