Skip to content

replace controlTypes.STATE_* with controlTypes.State.*#12712

Merged
feerrenrut merged 5 commits into
masterfrom
STATE-to-State
Aug 10, 2021
Merged

replace controlTypes.STATE_* with controlTypes.State.*#12712
feerrenrut merged 5 commits into
masterfrom
STATE-to-State

Conversation

@seanbudd

@seanbudd seanbudd commented Aug 5, 2021

Copy link
Copy Markdown
Member

Link to issue number:

Part of #12549

Summary of the issue:

controlTypes.STATE_* are deprecated, to be replaced by controlTypes.State.*

Description of how this pull request fixes the issue:

  • replaces all instances of controlTypes.STATE_ with controlTypes.State. across .py files
  • search and manually replace final STATE_ constant usages
    • Searched using the regex [^\.]\bSTATE_, which finds STATE_ instances
      where:
      • it is not of the form <Foo>.STATE_ (as oleacc.STATE_* exists)
      • STATE_ is the prefix of the symbol (as IA2_STATE_* 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 and negativeDisplayString 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

Searched using the regex [^\.]\bSTATE_, which finds STATE_ instances
where
* it is not of the form <Foo>.STATE_ (as oleacc.STATE_* exists)
* STATE_ is the prefix of the symbol (as IA2_STATE_* exists)

Replaced the remaining instances manually where required.
Fixes unit tests to cover new usages and legacy usages.
@AppVeyorBot

Copy link
Copy Markdown

See test results for failed build of commit 213fb3dfb0

@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.

Overall looks good.

I've been thinking "how do we prevent new code from using the old STATE_* constants?" Perhaps we could extend the lint check (which already creates a diff), then regex on that diff looking for STATE_* constants.

Comment thread source/appModules/powerpnt.py Outdated
@seanbudd

seanbudd commented Aug 9, 2021

Copy link
Copy Markdown
Member Author

I've been thinking "how do we prevent new code from using the old STATE_* constants?" Perhaps we could extend the lint check (which already creates a diff), then regex on that diff looking for STATE_* constants.

How would we determine STATE_* constant usage? Right now it is manual confirmation (with a regex guide).

Once this is merged in, we could replace the mapping STATE_* = State.* with the following idea from @LeonarddeR #12649 (comment), and it would be less noisy. This is a suggested usage of PEP-562.

def __getattr__(name: str) -> Any:
	if name.startswith("STATE_"):
		log.error("Deprecated constant used")
		return getattr(State, name.split("_", 1)[-1])

@AppVeyorBot

Copy link
Copy Markdown

See test results for failed build of commit 5408e6d2b8

@lukaszgo1

Copy link
Copy Markdown
Contributor

I've been thinking "how do we prevent new code from using the old STATE_* constants?" Perhaps we could extend the lint check (which already creates a diff), then regex on that diff looking for STATE_* constants.

How would we determine STATE_* constant usage? Right now it is manual confirmation (with a regex guide).

Cannot we just search for every STATE_* in the diff? I agree that is not very efficient but much better than the alternative below.

Once this is merged in, we could replace the mapping STATE_* = State.* with the following idea from @LeonarddeR #12649 (comment), and it would be less noisy.

Less noisy for core but horribly annoying for add-ons making Alphas pretty unusable - imagine getting error sound every once in a while just because many add-ons are not going to use new enum's before 2022.1.

@LeonarddeR

Copy link
Copy Markdown
Collaborator

Once this is merged in, we could replace the mapping STATE_* = State.* with the following idea from @LeonarddeR #12649 (comment), and it would be less noisy.

Less noisy for core but horribly annoying for add-ons making Alphas pretty unusable - imagine getting error sound every once in a while just because many add-ons are not going to use new enum's before 2022.1.

Not noisy at all if we lower the error level a bit.

@lukaszgo1

Copy link
Copy Markdown
Contributor

Not noisy at all if we lower the error level a bit.

That is an option but this means that usage of the oldd constants would be harder to check for new PR's. Essentially looking for them in the diff seems to be a better option than inspecting the log as the latter solution cannot be automated.

@seanbudd

seanbudd commented Aug 10, 2021

Copy link
Copy Markdown
Member Author

Cannot we just search for every STATE_* in the diff? I agree that is not very efficient but much better than the alternative below.

There could be false positives here, eg "oleacc.STATE_*" and "IA2_STATE_*".

Not noisy at all if we lower the error level a bit.

Or if we only perform an error beep on the first runtime usage of a particular constant or group of constants.

@feerrenrut

Copy link
Copy Markdown
Contributor

How would we determine STATE_* constant usage? Right now it is manual confirmation (with a regex guide).

By running a regex against the PR diff (Only lines changed, the same as the linter does).

There could be false positives here, eg "oleacc.STATE_" and "IA2_STATE_".

  • Tighten up the regex
  • Have a way to exclude a line / or mark as a false positive.

@seanbudd

Copy link
Copy Markdown
Member Author

@feerrenrut - this will require a force merge as the lint check will not pass

@seanbudd

Copy link
Copy Markdown
Member Author
  • Have a way to exclude a line / or mark as a false positive.

I think we can do both, and something like marking it with a comment # ignore deprecation warning.

Would adding the warnings/errors be a good idea too? I think it would be better to move to the PEP standard, and update deprecations.md.

@feerrenrut feerrenrut merged commit 17e5286 into master Aug 10, 2021
@feerrenrut feerrenrut deleted the STATE-to-State branch August 10, 2021 03:04
@nvaccessAuto nvaccessAuto added this to the 2021.3 milestone Aug 10, 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.

6 participants