-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from cwstryker/cwstryker/generic_types
One option for adding generic types
- Loading branch information
Showing
4 changed files
with
67 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from typing import Callable, Protocol, TypeVar, Union | ||
|
||
from typing_extensions import TypeAlias | ||
from wpimath.controller import ProfiledPIDController, ProfiledPIDControllerRadians | ||
from wpimath.trajectory import TrapezoidProfile, TrapezoidProfileRadians | ||
|
||
# Generic Types | ||
TProfiledPIDController = TypeVar( | ||
"TProfiledPIDController", ProfiledPIDControllerRadians, ProfiledPIDController | ||
) | ||
TTrapezoidProfileState = TypeVar( | ||
"TTrapezoidProfileState", | ||
TrapezoidProfileRadians.State, | ||
TrapezoidProfile.State, | ||
) | ||
|
||
|
||
# Protocols - Structural Typing | ||
class UseOutputFunction(Protocol): | ||
|
||
def __init__(self, *args, **kwargs) -> None: ... | ||
|
||
def __call__(self, t: float, u: TTrapezoidProfileState) -> None: ... | ||
|
||
def accept(self, t: float, u: TTrapezoidProfileState) -> None: ... | ||
|
||
|
||
# Type Aliases | ||
FloatSupplier: TypeAlias = Callable[[], float] | ||
FloatOrFloatSupplier: TypeAlias = Union[float, Callable[[], float]] |