Skip to content

Conversation

@texasaggie97-zz
Copy link
Contributor

@texasaggie97-zz texasaggie97-zz commented Nov 10, 2020

  • This contribution adheres to CONTRIBUTING.md.
  • I've updated CHANGELOG.md if applicable.
  • I've added tests applicable for this pull request

What does this Pull Request accomplish?

  • Add type hints to public API
    • Uses type_in_documentation metadata since it mostly has the information needed - we need the complete list of possible types in the API, not just the type that is passed into the DLL
    • Several special cases to deal with free form test
    • Not sure how to put this information into the metadata
  • Most type hints are calculated
  • A few in fancy functions are hardcoded
  • The preferred method for type hinting namedtuples is to create a class that inherits from typing.NamedTuple. This would require the couple of namedtuples we have to be moved to custom types. I did not do that work for this PR.

List issues fixed by this Pull Request below, if any.

What testing has been done?

  • Unit tests and flake8 still pass with type hinting added
  • Need to add mypy tests, maybe using examples?

@codecov
Copy link

codecov bot commented Nov 10, 2020

Codecov Report

Merging #1530 (28c9e39) into master (be1d5aa) will decrease coverage by 0.33%.
The diff coverage is 87.32%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1530      +/-   ##
==========================================
- Coverage   91.66%   91.33%   -0.34%     
==========================================
  Files          20       20              
  Lines        3457     3510      +53     
==========================================
+ Hits         3169     3206      +37     
- Misses        288      304      +16     
Flag Coverage Δ
codegenunittests 87.75% <64.70%> (-0.52%) ⬇️
nifakeunittests 96.35% <100.00%> (+<0.01%) ⬆️
nimodinstunittests 95.40% <100.00%> (+0.02%) ⬆️
nitclkunittests 95.65% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
build/helper/codegen_helper.py 90.22% <7.69%> (-2.30%) ⬇️
build/helper/metadata_add_all.py 81.85% <83.78%> (+0.50%) ⬆️
build/helper/__init__.py 100.00% <100.00%> (ø)
generated/nifake/nifake/session.py 97.71% <100.00%> (+<0.01%) ⬆️
generated/nimodinst/nimodinst/session.py 95.40% <100.00%> (+0.02%) ⬆️
generated/nitclk/nitclk/session.py 95.65% <100.00%> (+0.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update be1d5aa...28c9e39. Read the comment docs.

@codecov-commenter
Copy link

codecov-commenter commented Jul 21, 2025

Codecov Report

❌ Patch coverage is 87.32394% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.33%. Comparing base (be1d5aa) to head (28c9e39).
⚠️ Report is 342 commits behind head on master.

Files with missing lines Patch % Lines
build/helper/codegen_helper.py 7.69% 12 Missing ⚠️
build/helper/metadata_add_all.py 83.78% 6 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1530      +/-   ##
==========================================
- Coverage   91.66%   91.33%   -0.34%     
==========================================
  Files          20       20              
  Lines        3457     3510      +53     
==========================================
+ Hits         3169     3206      +37     
- Misses        288      304      +16     
Flag Coverage Δ
codegenunittests 87.75% <64.70%> (-0.52%) ⬇️
nifakeunittests 96.35% <100.00%> (+<0.01%) ⬆️
nimodinstunittests 95.40% <100.00%> (+0.02%) ⬆️
nitclkunittests 95.65% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
build/helper/__init__.py 100.00% <100.00%> (ø)
generated/nifake/nifake/session.py 97.71% <100.00%> (+<0.01%) ⬆️
generated/nimodinst/nimodinst/session.py 95.40% <100.00%> (+0.02%) ⬆️
generated/nitclk/nitclk/session.py 95.65% <100.00%> (+0.03%) ⬆️
build/helper/metadata_add_all.py 81.85% <83.78%> (+0.50%) ⬆️
build/helper/codegen_helper.py 90.22% <7.69%> (-2.30%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update be1d5aa...28c9e39. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

'''
import collections
Measurement = collections.namedtuple('Measurement', ['voltage', 'current', 'in_compliance'])
measurement = typing.NamedTuple('Measurement', [('voltage', 'float'), ('current', 'float'), ('in_compliance', 'bool')])
Copy link
Contributor

@bkeryan bkeryan Jul 21, 2025

Choose a reason for hiding this comment

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

The preferred method for type hinting namedtuples is to create a class that inherits from typing.NamedTuple. This would require the couple of namedtuples we have to be moved to custom types. I did not do that work for this PR.

FYI, there is a separate GitHub issue about that: #1885

return attribute_value_ctype.value.decode(self._encoding)

def _open_installed_devices_session(self, driver):
def _open_installed_devices_session(self, driver: str) -> typing.Tuple[int, int]:
Copy link
Contributor

Choose a reason for hiding this comment

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

typing.Tuple, typing.List, typing.Dict, etc. are deprecated in Python 3.9 and later. Use tuple[T], list[T], dict[K,V], etc.

''' These are code-generated '''

def _get_error(self, error_description_size=[1024]):
def _get_error(self, error_description_size: typing.Iterable[int] = [1024]) -> typing.Tuple[int, str]:
Copy link
Contributor

Choose a reason for hiding this comment

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

collections.abc.Iterable[T]

return int(vi_ctype.value)

def wait_for_debounce(self, maximum_time_ms=hightime.timedelta(milliseconds=-1)):
def wait_for_debounce(self, maximum_time_ms: typing.Union['hightime.timedelta', 'datetime.timedelta', int] = hightime.timedelta(milliseconds=-1)) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI, if you use from __future__ import annotations, you can write this as maximum_time_ms: hightime.timedelta | datetime.timedelta | int even though Python 3.9 does not support the new union syntax.

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.

3 participants