Skip to content
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

Add mypy typing support #57

Merged
merged 2 commits into from
Jan 24, 2022
Merged

Conversation

brent-stone
Copy link

Initial type stubs for compatibility with mypy for downstream projects relying on can-isotp.

isotp.tpsock.opts typing is left mostly unfinished and there may be a few inaccuracies in the other .pyi proposals.

Brent Stone added 2 commits January 22, 2022 21:17
Initial type stubs for compatibility with mypy for downstream projects relying on can-isotp.

isotp.tpsock.opts typing is left mostly unfinished and there may be a few inaccuracies in the other .pyi proposals.
rxfn callable needed an Optional added to the return type of CanMessage: 

rxfn: Optional[Callable[[], Optional[CanMessage]]]
@pylessard
Copy link
Owner

Hi @brent-stone ,
I do not know about mypi. Please educate me.

  • What's the purpose of this?
  • I see that it add extra files but does not modify the source code, is that what should be expected.
  • What could be the drawback of not having the .pyi up to date? How does it affect functionality?
  • Do you think this should be added to documentation as well?

Regards

@brent-stone
Copy link
Author

brent-stone commented Jan 23, 2022

Hi. There's no effect to anyone not using mypy or other modern python dev tools. For those that are, they'll be able to do automated bug checking thanks to these .pyi descriptions.

Documentation can be automatically generated using the source code and stub files using sphinx if you decide to go that route.

The downside of the .pyi files getting out of synch with the source is those downstream projects relying on type checking may get bugs... but that's true anytime someone moves to a new release of a package without rerunning their tests.

For what it's worth, Bus, CanStack, CanMessage, and a few other exposed data structures like error_handler and rxfn, txfn, are all that's needed for downstream type checking here. I went a little extra using mypy's stubgen tool then manually cleaning up parameter and return type hinting with what's actually used in the package.

@pylessard
Copy link
Owner

Nice stuff.
Thank you for your contribution

@pylessard pylessard merged commit f03e5e5 into pylessard:master Jan 24, 2022
@pylessard pylessard mentioned this pull request Jan 24, 2022
@pylessard
Copy link
Owner

Wow, Sublime Text now gives me hint about my own code.
it was about time I learn about this. Thank you!

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

Successfully merging this pull request may close these issues.

None yet

2 participants