-
Notifications
You must be signed in to change notification settings - Fork 30
Add more type hints #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
auscompgeek
wants to merge
1
commit into
robotpy:main
Choose a base branch
from
auscompgeek:types
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add more type hints #122
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,11 @@ | ||
from typing import Sequence, Union | ||
|
||
ValueT = Union[ | ||
bool, | ||
float, | ||
str, | ||
bytes, | ||
Sequence[bool], | ||
Sequence[float], | ||
Sequence[str], | ||
] |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,15 +1,19 @@ | ||
# todo: tracks NetworkTablesInstance.java | ||
|
||
from typing import Any, Callable, List, Optional, Sequence, Tuple, Union | ||
import logging | ||
import typing | ||
from typing import Callable, List, Optional, Sequence, Tuple, Union | ||
from weakref import WeakSet | ||
|
||
from ._impl import constants | ||
from ._impl.api import NtCoreApi | ||
|
||
from .entry import NetworkTableEntry | ||
from .table import NetworkTable | ||
from .types import ValueT | ||
|
||
import logging | ||
if typing.TYPE_CHECKING: | ||
from networktables.util import _NtProperty | ||
|
||
logger = logging.getLogger("nt") | ||
|
||
|
@@ -48,7 +52,7 @@ class NetworkTablesInstance: | |
instances is for unit testing, but they can also enable one program to | ||
connect to two different NetworkTables networks. | ||
|
||
The global "default" instance (as returned by :meth:`.NetworkTablesInstance.getDefault`) is | ||
The global "default" instance (as returned by :meth:`.getDefault`) is | ||
always available, and is intended for the common case when there is only | ||
a single NetworkTables instance being used in the program. | ||
|
||
|
@@ -164,17 +168,16 @@ def getDefault(cls) -> "NetworkTablesInstance": | |
cls._defaultInstance = cls() | ||
return cls._defaultInstance | ||
|
||
def __init__(self): | ||
def __init__(self) -> None: | ||
self._init() | ||
|
||
def _init(self): | ||
def _init(self) -> None: | ||
self._api = NtCoreApi(self.__createEntry) | ||
self._tables = {} | ||
self._entry_listeners = {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Turns out this is completely unused. |
||
self._conn_listeners = {} | ||
self._tables = {} # type: typing.Dict[str, NetworkTable] | ||
self._conn_listeners = {} # type: typing.Dict[Callable, List[int]] | ||
|
||
if not hasattr(self, "_ntproperties"): | ||
self._ntproperties = WeakSet() | ||
self._ntproperties = WeakSet() # type: WeakSet[_NtProperty] | ||
else: | ||
for ntprop in self._ntproperties: | ||
ntprop.reset() | ||
|
@@ -202,7 +205,6 @@ def getEntries(self, prefix: str, types: int = 0) -> Sequence[NetworkTableEntry] | |
starts with this string are returned | ||
:param types: bitmask of types; 0 is treated as a "don't care" | ||
:returns: List of matching entries. | ||
:rtype: list of :class:`.NetworkTableEntry` | ||
|
||
.. versionadded:: 2018.0.0 | ||
""" | ||
|
@@ -263,7 +265,7 @@ def deleteAllEntries(self) -> None: | |
|
||
def addEntryListener( | ||
self, | ||
listener: Callable[[str, Any, int], None], | ||
listener: Callable[[str, ValueT, int], None], | ||
immediateNotify: bool = True, | ||
localNotify: bool = True, | ||
paramIsNew: bool = True, | ||
|
@@ -306,7 +308,7 @@ def addEntryListener( | |
|
||
def addEntryListenerEx( | ||
self, | ||
listener: Callable[[str, Any, int], None], | ||
listener: Callable[[str, ValueT, int], None], | ||
flags: int, | ||
paramIsNew: bool = True, | ||
) -> None: | ||
|
@@ -341,7 +343,7 @@ def addEntryListenerEx( | |
addGlobalListener = addEntryListener | ||
addGlobalListenerEx = addEntryListenerEx | ||
|
||
def removeEntryListener(self, listener: Callable[[str, Any, int], None]) -> None: | ||
def removeEntryListener(self, listener: Callable[[str, ValueT, int], None]) -> None: | ||
"""Remove an entry listener. | ||
|
||
:param listener: Listener to remove | ||
|
@@ -445,7 +447,7 @@ def startServer( | |
persistFilename: str = "networktables.ini", | ||
listenAddress: str = "", | ||
port: int = constants.NT_DEFAULT_PORT, | ||
): | ||
) -> bool: | ||
"""Starts a server using the specified filename, listening address, and port. | ||
|
||
:param persistFilename: the name of the persist file to use | ||
|
@@ -467,7 +469,7 @@ def stopServer(self) -> None: | |
def startClient( | ||
self, | ||
server_or_servers: Union[str, ServerPortPair, List[ServerPortPair], List[str]], | ||
): | ||
) -> bool: | ||
"""Sets server addresses and port for client (without restarting client). | ||
The client will attempt to connect to each server in round robin fashion. | ||
|
||
|
@@ -479,7 +481,7 @@ def startClient( | |
self.setServer(server_or_servers) | ||
return self._api.startClient() | ||
|
||
def startClientTeam(self, team: int, port: int = constants.NT_DEFAULT_PORT): | ||
def startClientTeam(self, team: int, port: int = constants.NT_DEFAULT_PORT) -> bool: | ||
"""Starts a client using commonly known robot addresses for the specified | ||
team. | ||
|
||
|
@@ -580,7 +582,6 @@ def getConnections(self) -> Sequence: | |
If operating as a client, this will return either zero or one values. | ||
|
||
:returns: list of connection information | ||
:rtype: list | ||
|
||
.. versionadded:: 2018.0.0 | ||
""" | ||
|
@@ -657,15 +658,14 @@ def loadEntries(self, filename: str, prefix: str): | |
# These methods are unique to pynetworktables | ||
# | ||
|
||
def initialize(self, server=None): | ||
def initialize(self, server: Optional[str] = None) -> bool: | ||
"""Initializes NetworkTables and begins operations | ||
|
||
:param server: If specified, NetworkTables will be set to client | ||
mode and attempt to connect to the specified server. | ||
This is equivalent to executing:: | ||
|
||
self.startClient(server) | ||
:type server: str | ||
|
||
:returns: True if initialized, False if already initialized | ||
|
||
|
@@ -691,7 +691,7 @@ def shutdown(self) -> None: | |
|
||
self._init() | ||
|
||
def startTestMode(self, server: bool = True): | ||
def startTestMode(self, server: bool = True) -> bool: | ||
"""Setup network tables to run in unit test mode, and enables verbose | ||
logging. | ||
|
||
|
@@ -736,8 +736,6 @@ def getGlobalAutoUpdateValue( | |
:param defaultValue: The default value to return if the key doesn't exist | ||
:param writeDefault: If True, force the value to the specified default | ||
|
||
:rtype: :class:`.NetworkTableEntry` | ||
|
||
.. seealso:: :func:`.ntproperty` is a read-write alternative to this | ||
|
||
.. versionadded:: 2015.3.0 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wtf is this extra file for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Breaking what would otherwise be a cyclic import. I'd just put this at
networktables/types.py
, but… yeah.