Skip to content

Add typing annotations for can.notifier #679

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

Merged
merged 2 commits into from
Aug 15, 2019

Conversation

karlding
Copy link
Collaborator

@karlding karlding commented Aug 8, 2019

This adds typing annotations for functions in can.notifier.

In addition, this remove the redundant typing information that was
previously in the docstring, since we now have sphinx-autodoc-typehints
to generate the types for the docs from the annotations in the function
signature.

This works towards PEP 561 compatibility.

This adds typing annotations for functions in can.notifier.

In addition, this remove the redundant typing information that was
previously in the docstring, since we now have sphinx-autodoc-typehints
to generate the types for the docs from the annotations in the function
signature.

This works towards PEP 561 compatibility.
@karlding karlding requested review from hardbyte and felixdivo August 8, 2019 07:10
if (
self._loop is not None
and hasattr(bus, "fileno")
and bus.fileno() >= 0 # type: ignore
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is disabled here because mypy doesn't really deal well with hasattr checks. See the discussion here. We could either:

  1. Disable the type checker (like is done here)
  2. Perform the cast to Any
  3. Refactor the code to have fileno on the base class return None by default (which we can check for), and then subclasses provide their own implementation as needed

I'm personally inclined to 3, but that's a bit more involved than the other 2 (and perhaps should be kept out of this change). Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I vote for 3, but it can return -1 instead of None.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd vote for 1. It's just a shortcoming of the type system, and no problem with our API.

Copy link
Owner

Choose a reason for hiding this comment

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

I agree that one makes sense for this PR, but 3 would be the best long term solution.

@codecov
Copy link

codecov bot commented Aug 8, 2019

Codecov Report

Merging #679 into develop will increase coverage by <.01%.
The diff coverage is 89.47%.

@@             Coverage Diff             @@
##           develop     #679      +/-   ##
===========================================
+ Coverage    68.74%   68.75%   +<.01%     
===========================================
  Files           69       69              
  Lines         6235     6240       +5     
===========================================
+ Hits          4286     4290       +4     
- Misses        1949     1950       +1

@codecov
Copy link

codecov bot commented Aug 8, 2019

Codecov Report

Merging #679 into develop will increase coverage by <.01%.
The diff coverage is 89.47%.

@@             Coverage Diff             @@
##           develop     #679      +/-   ##
===========================================
+ Coverage    68.74%   68.75%   +<.01%     
===========================================
  Files           69       69              
  Lines         6235     6240       +5     
===========================================
+ Hits          4286     4290       +4     
- Misses        1949     1950       +1

@felixdivo felixdivo added this to the 4.0 Release milestone Aug 11, 2019
@hardbyte hardbyte merged commit e6f3453 into hardbyte:develop Aug 15, 2019
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.

4 participants