Skip to content

Add Typing to getTextWithFields#12969

Merged
feerrenrut merged 6 commits into
masterfrom
addTyping-getTextWithFields
Nov 24, 2021
Merged

Add Typing to getTextWithFields#12969
feerrenrut merged 6 commits into
masterfrom
addTyping-getTextWithFields

Conversation

@feerrenrut

Copy link
Copy Markdown
Contributor

Link to issue number:

Noticed during investigation of #12919

Summary of the issue:

getTextWithFields is expected to return TextWithFieldsT which is a List[Union[str, FieldCommand]]
Many of the overrides of getTextWithFields didn't specify the type, thus did not benefit from type hinting, some of them
return incorrect types.

Description of how this pull request fixes the issue:

  • add type info to all definitions of getTextWithFields
  • Ensure that where the helper function _getFieldsInRange is used, it must return TextWithFieldsT
  • Make _getFieldsInRange easier to read, break out the normalization of commands.
  • Handle any None values to return TextInfo.TextWithFieldsT

Note _getFieldsInRange was in one case returning an empty string, not a list with an empty string, this has been resolved.

Testing strategy:

Test early on alpha.

Known issues with pull request:

The _getFieldsInRange empty string may have been treated as an empty iterable, in which case the more correct modification would be to return an empty list.

Change log entries:

None

Code Review Checklist:

  • Pull Request description:
    • description is up to date
    • change log entries
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • API is compatible with existing add-ons.
  • Documentation:
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English

TextWithFieldsT is List[Union[str, FieldCommand]]

getTextWithFields returns the result directly and has type annotation
declaring it returns TextWithFieldsT.

Other usages of _getFieldsInRange seem to filter out None, although
it is hard to be conclusive about this.
Note that XMLTextParser().parse
returns List[Union[FieldCommand, Optional[str]]]

TextInfo.TextWithFieldsT is str not optional:
List[Union[str, FieldCommand]]

@michaelDCurran michaelDCurran left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Other than the extra list, I'm happy with all of this.

Comment thread source/virtualBuffers/__init__.py Outdated
@feerrenrut feerrenrut merged commit 2330a74 into master Nov 24, 2021
@feerrenrut feerrenrut deleted the addTyping-getTextWithFields branch November 24, 2021 10:12
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