Skip to content

Commit a8ea4a1

Browse files
committed
Added @disjoint_base, improved __init__ signatures
1 parent e4604ef commit a8ea4a1

File tree

3 files changed

+72
-54
lines changed

3 files changed

+72
-54
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
ephem.tests.*
22
ephem.stars.k
33
ephem.stars.v
4+
ephem._libastro.Observer.__init__
5+
ephem.FixedBody.__init__
6+
ephem._libastro.FixedBody.__init__

stubs/ephem/ephem/__init__.pyi

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from collections.abc import Callable
22
from datetime import datetime as _datetime, timedelta as _timedelta, tzinfo as _tzinfo
3-
from typing import overload
4-
from typing_extensions import Never
3+
from typing import Final, NoReturn, overload
4+
from typing_extensions import Self
55

66
from . import _libastro
77

@@ -80,83 +80,83 @@ Moon = _libastro.Moon
8080

8181
# Dynamically created planet classes
8282
class Mercury(Planet):
83-
__planet__: int
83+
__planet__: Final = 0
8484

8585
class Venus(Planet):
86-
__planet__: int
86+
__planet__: Final = 1
8787

8888
class Mars(Planet):
89-
__planet__: int
89+
__planet__: Final = 2
9090

9191
class Uranus(Planet):
92-
__planet__: int
92+
__planet__: Final = 5
9393

9494
class Neptune(Planet):
95-
__planet__: int
95+
__planet__: Final = 6
9696

9797
class Pluto(Planet):
98-
__planet__: int
98+
__planet__: Final = 7
9999

100100
class Sun(Planet):
101-
__planet__: int
101+
__planet__: Final = 8
102102

103103
# Planet moon classes
104104
class Phobos(PlanetMoon):
105-
__planet__: int
105+
__planet__: Final = 10
106106

107107
class Deimos(PlanetMoon):
108-
__planet__: int
108+
__planet__: Final = 11
109109

110110
class Io(PlanetMoon):
111-
__planet__: int
111+
__planet__: Final = 12
112112

113113
class Europa(PlanetMoon):
114-
__planet__: int
114+
__planet__: Final = 13
115115

116116
class Ganymede(PlanetMoon):
117-
__planet__: int
117+
__planet__: Final = 14
118118

119119
class Callisto(PlanetMoon):
120-
__planet__: int
120+
__planet__: Final = 15
121121

122122
class Mimas(PlanetMoon):
123-
__planet__: int
123+
__planet__: Final = 16
124124

125125
class Enceladus(PlanetMoon):
126-
__planet__: int
126+
__planet__: Final = 17
127127

128128
class Tethys(PlanetMoon):
129-
__planet__: int
129+
__planet__: Final = 18
130130

131131
class Dione(PlanetMoon):
132-
__planet__: int
132+
__planet__: Final = 19
133133

134134
class Rhea(PlanetMoon):
135-
__planet__: int
135+
__planet__: Final = 20
136136

137137
class Titan(PlanetMoon):
138-
__planet__: int
138+
__planet__: Final = 21
139139

140140
class Hyperion(PlanetMoon):
141-
__planet__: int
141+
__planet__: Final = 22
142142

143143
class Iapetus(PlanetMoon):
144-
__planet__: int
144+
__planet__: Final = 23
145145

146146
class Ariel(PlanetMoon):
147-
__planet__: int
147+
__planet__: Final = 24
148148

149149
class Umbriel(PlanetMoon):
150-
__planet__: int
150+
__planet__: Final = 25
151151

152152
class Titania(PlanetMoon):
153-
__planet__: int
153+
__planet__: Final = 26
154154

155155
class Oberon(PlanetMoon):
156-
__planet__: int
156+
__planet__: Final = 27
157157

158158
class Miranda(PlanetMoon):
159-
__planet__: int
159+
__planet__: Final = 28
160160

161161
# Newton's method
162162
def newton(f: Callable[[float], float], x0: float, x1: float, precision: float = ...) -> float: ...
@@ -205,8 +205,7 @@ class Observer(_libastro.Observer):
205205

206206
name: object
207207

208-
def __init__(self, /, *args: object, **kwargs: object) -> None: ...
209-
def copy(self) -> Observer: ...
208+
def copy(self) -> Self: ...
210209
__copy__ = copy
211210
def compute_pressure(self) -> None: ...
212211
def previous_transit(self, body: Body, start: _libastro._DateInitType | None = None) -> Date: ...
@@ -227,7 +226,7 @@ def localtime(date: Date | float) -> _datetime: ...
227226

228227
class _UTC(_tzinfo):
229228
ZERO: _timedelta
230-
def tzname(self, dt: _datetime | None, /) -> Never: ...
229+
def tzname(self, dt: _datetime | None, /) -> NoReturn: ...
231230
def utcoffset(self, dt: _datetime | None) -> _timedelta: ...
232231
def dst(self, dt: _datetime | None) -> _timedelta: ...
233232

stubs/ephem/ephem/_libastro.pyi

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from _typeshed import Unused
12
from datetime import datetime as _datetime
2-
from typing import TypedDict, overload
3-
from typing_extensions import Never, Self, TypeAlias, deprecated
3+
from typing import NoReturn, Protocol, TypedDict, overload, type_check_only
4+
from typing_extensions import Self, TypeAlias, deprecated, disjoint_base
45

56
_DateInitType: TypeAlias = (
67
Date
@@ -15,31 +16,31 @@ _DateInitType: TypeAlias = (
1516
| _datetime
1617
)
1718

19+
@type_check_only
1820
class _DateDescriptor:
1921
@overload
2022
def __get__(self, obj: None, objtype: type | None = None) -> Self: ...
2123
@overload
2224
def __get__(self, obj: object, objtype: type | None = None) -> Date: ...
2325
def __set__(self, obj: object, value: _DateInitType) -> None: ...
2426

25-
# Descriptor classes for angle attributes that accept float or string input
26-
# These descriptors don't actually exist at runtime but help type checkers
27-
# distinguish between the different angle storage formats used in the C extension
28-
27+
@type_check_only
2928
class _AngleDescriptorRadiansHours:
3029
@overload
3130
def __get__(self, obj: None, objtype: type | None = None) -> Self: ...
3231
@overload
3332
def __get__(self, obj: object, objtype: type | None = None) -> Angle: ...
3433
def __set__(self, obj: object, value: float | str) -> None: ...
3534

35+
@type_check_only
3636
class _AngleDescriptorRadiansDegrees:
3737
@overload
3838
def __get__(self, obj: None, objtype: type | None = None) -> Self: ...
3939
@overload
4040
def __get__(self, obj: object, objtype: type | None = None) -> Angle: ...
4141
def __set__(self, obj: object, value: float | str) -> None: ...
4242

43+
@type_check_only
4344
class _AngleDescriptorDegreesRadians:
4445
@overload
4546
def __get__(self, obj: None, objtype: type | None = None) -> Self: ...
@@ -58,8 +59,9 @@ meters_per_au: float
5859
moon_radius: float
5960
sun_radius: float
6061

61-
class Angle(float):
62-
def __new__(cls, *args: object, **kwargs: object) -> Never: ...
62+
@disjoint_base
63+
class Angle(float): # type: ignore[type-var]
64+
def __new__(cls, *args: Unused, **kwargs: Unused) -> NoReturn: ...
6365
@property
6466
def norm(self) -> Angle: ...
6567
@property
@@ -74,6 +76,7 @@ class Date(float):
7476
def tuple(self) -> tuple[int, int, int, int, int, float]: ...
7577
def datetime(self) -> _datetime: ...
7678

79+
@disjoint_base
7780
class Observer:
7881
lat: _AngleDescriptorRadiansDegrees
7982
lon: _AngleDescriptorRadiansDegrees
@@ -87,11 +90,12 @@ class Observer:
8790
epoch: _DateDescriptor
8891
date: _DateDescriptor
8992

90-
def __init__(self, /, *args: object, **kwargs: object) -> None: ...
93+
def __init__(self) -> None: ...
9194
def sidereal_time(self) -> Angle: ...
9295
def radec_of(self, az: float | str, alt: float | str) -> tuple[Angle, Angle]: ...
9396

94-
class Body:
97+
@disjoint_base
98+
class Body(Protocol):
9599
@property
96100
def name(self) -> str | None: ...
97101
@property
@@ -138,7 +142,7 @@ class Body:
138142
def circumpolar(self) -> bool: ...
139143
@property
140144
def neverup(self) -> bool: ...
141-
def __init__(self, *args: object, **kwargs: object) -> Never: ...
145+
def __init__(self, *args: Unused, **kwargs: Unused) -> None: ...
142146
def __copy__(self) -> Self: ...
143147
@overload
144148
def compute(self, observer: Observer, /) -> None: ...
@@ -148,7 +152,7 @@ class Body:
148152
def writedb(self) -> str: ...
149153
def parallactic_angle(self) -> Angle: ...
150154

151-
class Planet(Body):
155+
class Planet(Body, Protocol):
152156
@property
153157
def hlon(self) -> Angle: ...
154158
@property
@@ -161,8 +165,14 @@ class Planet(Body):
161165
def phase(self) -> float: ...
162166
@property
163167
def hlong(self) -> Angle: ...
164-
def __init__(self, /, *args: object, **kwargs: object) -> Never: ...
168+
@overload
169+
def __init__(self, observer: Observer, /) -> None: ...
170+
@overload
171+
def __init__(self, when: _DateInitType, /, epoch: _DateInitType = ...) -> None: ...
172+
@overload
173+
def __init__(self, *args: Unused, **kwargs: Unused) -> None: ...
165174

175+
@disjoint_base
166176
class Moon(Planet):
167177
@property
168178
def libration_lat(self) -> Angle: ...
@@ -174,23 +184,23 @@ class Moon(Planet):
174184
def moon_phase(self) -> float: ...
175185
@property
176186
def subsolar_lat(self) -> Angle: ...
177-
def __init__(self, /, *args: object, **kwargs: object) -> None: ...
178187

188+
@disjoint_base
179189
class Jupiter(Planet):
180190
@property
181191
def cmlI(self) -> Angle: ...
182192
@property
183193
def cmlII(self) -> Angle: ...
184-
def __init__(self, /, *args: object, **kwargs: object) -> None: ...
185194

195+
@disjoint_base
186196
class Saturn(Planet):
187197
@property
188198
def earth_tilt(self) -> Angle: ...
189199
@property
190200
def sun_tilt(self) -> Angle: ...
191-
def __init__(self, /, *args: object, **kwargs: object) -> None: ...
192201

193-
class PlanetMoon:
202+
@disjoint_base
203+
class PlanetMoon(Protocol):
194204
@property
195205
def name(self) -> str: ...
196206
@property
@@ -219,7 +229,12 @@ class PlanetMoon:
219229
def earth_visible(self) -> float: ...
220230
@property
221231
def sun_visible(self) -> float: ...
222-
def __init__(self, /, *args: object, **kwargs: object) -> Never: ...
232+
@overload
233+
def __init__(self, observer: Observer, /) -> None: ...
234+
@overload
235+
def __init__(self, when: _DateInitType, /, epoch: _DateInitType = ...) -> None: ...
236+
@overload
237+
def __init__(self, **kwargs: Unused) -> None: ...
223238
def __copy__(self) -> Self: ...
224239
@overload
225240
def compute(self, observer: Observer, /) -> None: ...
@@ -242,7 +257,7 @@ class FixedBody(Body):
242257
_pmdec: float
243258
_class: str
244259

245-
def __init__(self, /, *args: object, **kwargs: object) -> None: ...
260+
def __init__(self) -> None: ...
246261

247262
class EllipticalBody(Planet):
248263
name: str | None
@@ -260,7 +275,7 @@ class EllipticalBody(Planet):
260275
_size: float
261276
_e: float
262277

263-
def __init__(self, /, *args: object, **kwargs: object) -> None: ...
278+
def __init__(self, *args: Unused, **kwargs: Unused) -> None: ...
264279

265280
class ParabolicBody(Planet):
266281
name: str | None
@@ -274,7 +289,7 @@ class ParabolicBody(Planet):
274289
_k: float
275290
_size: float
276291

277-
def __init__(self, /, *args: object, **kwargs: object) -> None: ...
292+
def __init__(self, *args: Unused, **kwargs: Unused) -> None: ...
278293

279294
class HyperbolicBody(Planet):
280295
name: str | None
@@ -289,8 +304,9 @@ class HyperbolicBody(Planet):
289304
_k: float
290305
_size: float
291306

292-
def __init__(self, /, *args: object, **kwargs: object) -> None: ...
307+
def __init__(self, *args: Unused, **kwargs: Unused) -> None: ...
293308

309+
@disjoint_base
294310
class EarthSatellite(Body):
295311
name: str | None
296312
epoch: _DateDescriptor
@@ -327,8 +343,8 @@ class EarthSatellite(Body):
327343
def range_velocity(self) -> float: ...
328344
@property
329345
def eclipsed(self) -> bool: ...
330-
def __init__(self, /, *args: object, **kwargs: object) -> None: ...
331346

347+
@type_check_only
332348
class _MoonPhases(TypedDict):
333349
new: Date
334350
full: Date

0 commit comments

Comments
 (0)