8000 Add type hinting by ArchdukeTim · Pull Request #470 · robotpy/robotpy-wpilib · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Nov 13, 2023. It is now read-only.

Add type hinting #470

Merged
merged 15 commits into from
Dec 31, 2018
Merged

Add type hinting #470

merged 15 commits into from
Dec 31, 2018

Conversation

ArchdukeTim
Copy link
Contributor

No description provided.

Copy link
Member
@virtuald virtuald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, thank you for putting in the effort to do this. It's big but most of the changes are pretty uniform. I'd extract out the init stuff to a separate PR and see if that fixes the tests. I sorta feel the enum conversions should be separate too... but I dont mind it quite so much.

I think the next step is adding something that ensures any code in the repo that's added gets type hints, but we can save that for another day.

@auscompgeek
Copy link
Member

Is type hinting the initSendable methods really necessary? They're not really intended to be directly called by teams, and actually type hinting them requires adding all the SendableBuilder imports.

@virtuald
Copy link
Member

Given that we already import everything anyways, I don't see any harm in it.

@ArchdukeTim ArchdukeTim force-pushed the pep484 branch 3 times, most recently from 5231139 to 9f824ed Compare May 25, 2018 15:43
@ArchdukeTim
Copy link
Contributor Author

If someone could help me with these circular imports that'd be much appreciated

@auscompgeek
Copy link
Member

Either take a read of PEP 484, or just don't have circular imports in the first place.

@ArchdukeTim ArchdukeTim force-pushed the pep484 branch 3 times, most recently from 1504598 to a4e52f9 Compare May 26, 2018 23:02
@ArchdukeTim ArchdukeTim force-pushed the pep484 branch 2 times, most recently from a987396 to ecdef81 Compare May 27, 2018 02:06
@auscompgeek
Copy link
Member

You rebased the wrong way around.

@ArchdukeTim
Copy link
Contributor Author

I didn't pulll...idk how that happened

@auscompgeek
Copy link
Member

@virtuald Are you fine with making the type signatures in SmartDashboard API?

@virtuald
Copy link
Member

I think as long as we're not verifying the signatures automatically via mypy, that getting close enough is good enough. We can fix things piecemeal after this PR.

@auscompgeek
Copy link
Member

To me, "close enough" would be saying that we're only guaranteeing that putting a sequence on NetworkTables will work. Iterable seems pedantic and potentially confusing. Do we want to make the guarantee that iterables can always be put onto NetworkTables?

@ArchdukeTim
Copy link
Contributor Author

@auscompgeek when it puts things in networktables, it iterates over them and turns it into a tuple. The final product is a tuple, but any iterable will be able to be parsed

@auscompgeek
Copy link
Member

Yes, but a sequence is also iterable. We also haven't fully defined the types throughout all of pynetworktables (a bunch of which the documented types are wrong anyway).

My question still stands.

@virtuald
Copy link
Member

The implementation is at https://github.com/robotpy/pynetworktables/blob/59b5d1328274e78393202fe2a7e09845f5ff63a5/ntcore/value.py#L57 , using an iterable seems best?

@@ -5,8 +5,12 @@
# must be accompanied by the FIRST BSD license file in the root directory of
# the project.
# ----------------------------------------------------------------------------
from typing import TypeVar

V = TypeVar("V")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type variable isn't particularly useful if it doesn't tie any types together.

If this is intended to tie together the argument and return types for SendableChooser's methods, you might also want to make this type variable covariant.

(i.e. if I have a SendableChooser of SpeedControllers, I should be able to put in a Spark, get it back, and treat it as merely a SpeedController.)

Copy link
Contributor Author
@ArchdukeTim ArchdukeTim Dec 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't a spark fall under SpeedController since it's a subclass? I add a SpeedController object (which happens to be a spark), and I get back a speedcontroller object (that is also of type spark)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We appear to be in violent agreement with each other.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I didn't realize python had a special marking for this type of behavior. All these small quirks have made me wonder if I should've read through pep484 before implementing it...🤔

virtuald
virtuald previously approved these changes Dec 28, 2018
Copy link
Member
@virtuald virtuald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@virtuald virtuald merged commit 29845e2 into robotpy:master Dec 31, 2018
@virtuald
Copy link
Member

Any other nitpicks, make a new PR.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0