Skip to content

Replace internal controlTypes.ROLE_* usages with controlTypes.Role.*#12649

Merged
feerrenrut merged 8 commits into
masterfrom
ROLE-to-Role
Jul 27, 2021
Merged

Replace internal controlTypes.ROLE_* usages with controlTypes.Role.*#12649
feerrenrut merged 8 commits into
masterfrom
ROLE-to-Role

Conversation

@seanbudd

@seanbudd seanbudd commented Jul 15, 2021

Copy link
Copy Markdown
Member

Link to issue number:

Part of #12549

Summary of the issue:

controlTypes.ROLE_* are deprecated, to be replaced by controlTypes.Role.*

Description of how this pull request fixes the issue:

  • replaces all instances of controlTypes.ROLE_ with controlTypes.Role. across .py files
  • search and manually replace final ROLE_ constant usages
    • Searched using the regex [^\.]\bROLE_, which finds ROLE_ instances
      where:
      • it is not of the form <Foo>.ROLE_ (as oleacc.ROLE_* exists)
      • ROLE_ is the prefix of the symbol (as IA2_ROLE_* exists)

Testing strategy:

Manual testing

  • Confirm the above steps will not introduce issues, and cover all cases.
  • Reproduce those steps and perform a diff with this branch

Existing unit tests exist for controlTypes, new unit tests are written to ensure displayString works

Existing system tests will work as a basic smoke test for this core feature

Known issues with pull request:

The lint check is likely to fail

Change log entries:

None needed

Code Review Checklist:

  • Pull Request description is up to date.
  • Unit tests.
  • System (end to end) tests.
  • Manual testing.
  • User Documentation.
  • Change log entry.
  • Context sensitive help for GUI changes.
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers

seanbudd added 2 commits July 15, 2021 14:47
Searched using the regex [^\.]\bROLE_, which finds ROLE_ instances
where
* it is not of the form <Foo>.ROLE_ (as oleacc.ROLE_* exists)
* ROLE_ is the prefix of the symbol (as IA2_ROLE_* exists)

Replaced the remaining instances manually where required
@seanbudd seanbudd requested a review from a team as a code owner July 15, 2021 05:05
@seanbudd seanbudd requested a review from feerrenrut July 15, 2021 05:05
@seanbudd seanbudd changed the title Role to role Replace internal controlTypes.ROLE_* usages with controlTypes.Role.* Jul 15, 2021
@AppVeyorBot

Copy link
Copy Markdown

See test results for failed build of commit d1eb87db3a

@LeonarddeR

LeonarddeR commented Jul 15, 2021

Copy link
Copy Markdown
Collaborator

I wonder whether we could emit deprecation warnings for old constant use, e.g. by handling them using a module getattr. For example:

def __getattr__(name: str) -> Any:
	if name.startswith"ROLE_"):
		# Warn about deprecation!
		return getattr(Role, name.split("_", 1)[-1]

@josephsl

Copy link
Copy Markdown
Contributor

Hi,

I think we will come across linting issues for a while, given how controlTypes.ROLE_* and STATE_* are used in places where Flake8 complains about various issues.

Thanks.

@seanbudd

Copy link
Copy Markdown
Member Author

I wonder whether we could emit deprecation warnings for old constant use, e.g. by handling them using a module getattr. For example:

def __getattr__(name: str) -> Any:
	if name.startswith"ROLE_"):
		# Warn about deprecation!
		return getattr(Role, name.split("_", 1)[-1]

My first thought is that this would be way too noisy in this instance. I would want to do this for less integral parts of NVDA, or if the removal of the deprecation is delayed and most addons uses the new enums.

I think we will come across linting issues for a while, given how controlTypes.ROLE_* and STATE_* are used in places where Flake8 complains about various issues.

In this case I think it is best to be ignored and overridden with force merges.

@feerrenrut feerrenrut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Generally looks good. I've been through all the files.

A few files seem to have had their line endings modified, can you restore those?

Please don't force push, I'd like to be sure of which files have changed to make the follow up minimal.

Comment thread source/NVDAObjects/window/_msOfficeChart.py Outdated
Comment thread source/appModules/azardi-2_0.py
Comment thread source/appModules/bookshelf.py
Comment thread source/appModules/powerpnt.py Outdated
Comment thread source/appModules/powerpnt.py Outdated
Comment thread source/appModules/thunderbird.py Outdated
Comment thread source/NVDAObjects/__init__.py Outdated
def _get_role(self) -> int:
def _get_role(self) -> controlTypes.Role:
"""The role or type of control this object represents (example: button, list, dialog).
@return: a ROLE_* constant from L{controlTypes}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment should be updated as well to explain that now the role value comes from the enum

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't know what value that provides, the return type should make that clear hopefully

Comment thread tests/unit/test_controlTypes.py Outdated
@AppVeyorBot

Copy link
Copy Markdown

See test results for failed build of commit 6293c38132

@AppVeyorBot

Copy link
Copy Markdown

See test results for failed build of commit c207ea8abd

@seanbudd seanbudd requested a review from feerrenrut July 26, 2021 01:46
Comment on lines +23 to +27
def test_roleLabels(self):
"""Test to check whether every role has its own display string"""
for role in controlTypes.Role:
role.displayString

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you take a look to see if there is simple way to add a test for the corollary, that displayString raises when a label is missing?

If this test already exists, add a comment here to point it out.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't think there is a simple way, as new members cannot be added to Role at run time. I've added a generic test for displayString.
If one adds a role and forgets to add a label, this test should fail assuming the displayString test still passes.

@feerrenrut

Copy link
Copy Markdown
Contributor

Given the nature of this change, I think it is clearer not to try to address lint changes.

@seanbudd seanbudd requested a review from feerrenrut July 26, 2021 09:33
@AppVeyorBot

Copy link
Copy Markdown

See test results for failed build of commit 4c575f6ecb

Comment thread tests/unit/test_util/test_displayString.py Outdated

@feerrenrut feerrenrut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tests look good. Might as well fix that copyright year. But I'm happy for you to merge this.

@AppVeyorBot

Copy link
Copy Markdown

See test results for failed build of commit 3f943bbf64

@seanbudd

Copy link
Copy Markdown
Member Author

@feerrenrut can you merge this - I am unable with the failed lint check

@AppVeyorBot

Copy link
Copy Markdown

See test results for failed build of commit 3f943bbf64

@feerrenrut feerrenrut merged commit defed0e into master Jul 27, 2021
@feerrenrut feerrenrut deleted the ROLE-to-Role branch July 27, 2021 03:30
@nvaccessAuto nvaccessAuto added this to the 2021.3 milestone Jul 27, 2021
seanbudd pushed a commit that referenced this pull request Jul 29, 2024
Related to #12649, #12712, #12836

Summary of the issue:
The mentioned prs performed a large refactor with constant changes

Description of user facing changes
None known

Description of development approach
Add the mentioned PRs to .git-blame-ignore-revs to ensure a properly configured git blame will ignore these changes, revealing the history of the underlying code.
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.

7 participants