Miksus / rocketry

Modern scheduling library for Python
https://rocketry.readthedocs.io
MIT License
3.28k stars 108 forks source link

Mypy and type hints #172

Open mafrosis opened 1 year ago

mafrosis commented 1 year ago

Hello, great project!

I see most of the code has type hints, but I didn't obviously see mypy in play for type checking?

Adding a py.typed would be most welcome for other projects using mypy.

11: error: Skipping analyzing "rocketry": module is installed, but missing library stubs or py.typed marker  [import]
11: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-import

Further, I ran the stubgen tool locally to generate rocketry stubs for my project, but these stubs appear broken and generate all kinds of errors under mypy.

/mypy-stubs/rocketry/core/parameters/arguments.pyi:8: error: Name "rocketry.Session" is not defined  [name-defined]
/mypy-stubs/rocketry/_base.pyi:1: error: Module "rocketry" has no attribute "Session"; maybe "session"?  [attr-defined]
/mypy-stubs/rocketry/core/parameters/parameters.pyi:10: error: Name "rocketry.Session" is not defined  [name-defined]
/mypy-stubs/rocketry/core/condition/base.pyi:55: error: Signature of "get_state" incompatible with supertype "BaseCondition"  [override]
/mypy-stubs/rocketry/core/condition/base.pyi:55: note:      Superclass:
/mypy-stubs/rocketry/core/condition/base.pyi:55: note:          def get_state(self) -> Any
/mypy-stubs/rocketry/core/condition/base.pyi:55: note:      Subclass:
/mypy-stubs/rocketry/core/condition/base.pyi:55: note:          def get_state(self, res: int) -> Any
/mypy-stubs/rocketry/core/log/adapter.pyi:2: error: Skipping analyzing "redbird": module is installed, but missing library stubs or py.typed marker  [import]
/mypy-stubs/rocketry/core/task.pyi:10: error: Module "rocketry" has no attribute "Session"; maybe "session"?  [attr-defined]
/mypy-stubs/rocketry/core/schedule.pyi:2: error: Module "rocketry" has no attribute "Session"; maybe "session"?  [attr-defined]
/mypy-stubs/rocketry/session.pyi:9: error: Module "rocketry.parse" has no attribute "StaticParser"  [attr-defined]
/mypy-stubs/rocketry/time/delta.pyi:10: error: Incompatible types in assignment (expression has type "Union[datetime, Callable[..., Any]]", base class "TimeDelta" defined the type as "Optional[datetime]")  [assignment]
/mypy-stubs/rocketry/time/interval.pyi:44: error: Signature of "anchor_int" incompatible with supertype "AnchoredInterval"  [override]
/mypy-stubs/rocketry/time/interval.pyi:44: note:      Superclass:
/mypy-stubs/rocketry/time/interval.pyi:44: note:          def anchor_int(self, i: Any, side: Optional[Any] = ..., time_point: Optional[Any] = ..., **kwargs: Any) -> Any
/mypy-stubs/rocketry/time/interval.pyi:44: note:      Subclass:
/mypy-stubs/rocketry/time/interval.pyi:44: note:          def anchor_int(self, i: Any, side: Optional[Any] = ..., **kwargs: Any) -> Any
/mypy-stubs/rocketry/time/interval.pyi:53: error: Return type "None" of "rollforward" incompatible with return type "datetime" in supertype "TimeInterval"  [override]
/mypy-stubs/rocketry/conditions/meta.pyi:2: error: Module "rocketry" has no attribute "Session"; maybe "session"?  [attr-defined]
/mypy-stubs/rocketry/application.pyi:2: error: Skipping analyzing "redbird": module is installed, but missing library stubs or py.typed marker  [import]
/mypy-stubs/rocketry/application.pyi:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
/mypy-stubs/rocketry/application.pyi:3: error: Module "rocketry" has no attribute "Session"; maybe "session"?  [attr-defined]
/mypy-stubs/rocketry/__init__.pyi:8: error: Name "version" already defined (possibly by an import)  [no-redef]
/mypy-stubs/rocketry/__init__.pyi:10: error: Name "version_tuple" already defined (possibly by an import)  [no-redef]
/mypy-stubs/rocketry/tasks/maintain/os.pyi:5: error: Incompatible types in assignment (expression has type "str", base class "Task" defined the type as "Optional[Literal['main', 'async', 'thread', 'process']]")  [assignment]
/mypy-stubs/rocketry/tasks/maintain/os.pyi:11: error: Incompatible types in assignment (expression has type "str", base class "Task" defined the type as "Optional[Literal['main', 'async', 'thread', 'process']]")  [assignment]
Found 29 errors in 15 files (checked 10 source files)
djnnvx commented 1 year ago

I'm not too familiar with the stubgen tool but I can look into it when I have the time. Do you have a preferred documentation / tutorial to get into it?