Skip to content

Resolve method-field naming clashes in app commands and gateway modules - #188

Open
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260615-010121-468f317d
Open

Resolve method-field naming clashes in app commands and gateway modules#188
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260615-010121-468f317d

Conversation

@sonarqube-agent

Copy link
Copy Markdown

This PR was automatically created by the Remediation Agent's Scheduled backlog remediation feature.

Why these issues? These five BLOCKER-severity violations of rule python:S1845 are highly suitable for automation, all stemming from a single well-defined pattern: methods and fields differing only by capitalization. The fixes are concentrated in two files (installs.py and gateway.py) with straightforward, coherent refactoring that eliminates genuine code clarity issues.

Fixed five BLOCKER-severity SonarQube issues where method names clashed with field names differing only in capitalization. This involved refactoring context type constants in installs.py to module-level with underscore prefixes and renaming operation code fields in gateway.py to eliminate confusion and improve code clarity.

View Project in SonarCloud


Fixed Issues

python:S1845 - Rename method "guild" to prevent any misunderstanding/clash with field "GUILD" defined on line 128 • BLOCKERView issue

Location: discord/app_commands/installs.py:146

Why is this an issue?

Looking at the set of methods and fields in a class and finding two that differ only by capitalization is confusing to users of the class.

What changed

Introduces module-level constants _CONTEXT_TYPE_GUILD, _CONTEXT_TYPE_DM_CHANNEL, and _CONTEXT_TYPE_PRIVATE_CHANNEL outside the AppCommandContext class. These replace the class-level fields GUILD, DM_CHANNEL, and PRIVATE_CHANNEL that were causing name clashes with the methods guild(), dm_channel(), and private_channel() (which differ only by capitalization). By moving these constants out of the class with prefixed names, the naming conflicts are eliminated.

--- a/discord/app_commands/installs.py
+++ b/discord/app_commands/installs.py
@@ -112,0 +113,5 @@ class AppInstallationType:
+_CONTEXT_TYPE_GUILD: int = 0
+_CONTEXT_TYPE_DM_CHANNEL: int = 1
+_CONTEXT_TYPE_PRIVATE_CHANNEL: int = 2
+
+
python:S1845 - Rename method "dm_channel" to prevent any misunderstanding/clash with field "DM_CHANNEL" defined on line 129 • BLOCKERView issue

Location: discord/app_commands/installs.py:155

Why is this an issue?

Looking at the set of methods and fields in a class and finding two that differ only by capitalization is confusing to users of the class.

What changed

Introduces module-level constants _CONTEXT_TYPE_GUILD, _CONTEXT_TYPE_DM_CHANNEL, and _CONTEXT_TYPE_PRIVATE_CHANNEL outside the AppCommandContext class. These replace the class-level fields GUILD, DM_CHANNEL, and PRIVATE_CHANNEL that were causing name clashes with the methods guild(), dm_channel(), and private_channel() (which differ only by capitalization). By moving these constants out of the class with prefixed names, the naming conflicts are eliminated.

--- a/discord/app_commands/installs.py
+++ b/discord/app_commands/installs.py
@@ -112,0 +113,5 @@ class AppInstallationType:
+_CONTEXT_TYPE_GUILD: int = 0
+_CONTEXT_TYPE_DM_CHANNEL: int = 1
+_CONTEXT_TYPE_PRIVATE_CHANNEL: int = 2
+
+
python:S1845 - Rename method "private_channel" to prevent any misunderstanding/clash with field "PRIVATE_CHANNEL" defined on line 130 • BLOCKERView issue

Location: discord/app_commands/installs.py:164

Why is this an issue?

Looking at the set of methods and fields in a class and finding two that differ only by capitalization is confusing to users of the class.

What changed

Introduces module-level constants _CONTEXT_TYPE_GUILD, _CONTEXT_TYPE_DM_CHANNEL, and _CONTEXT_TYPE_PRIVATE_CHANNEL outside the AppCommandContext class. These replace the class-level fields GUILD, DM_CHANNEL, and PRIVATE_CHANNEL that were causing name clashes with the methods guild(), dm_channel(), and private_channel() (which differ only by capitalization). By moving these constants out of the class with prefixed names, the naming conflicts are eliminated.

--- a/discord/app_commands/installs.py
+++ b/discord/app_commands/installs.py
@@ -112,0 +113,5 @@ class AppInstallationType:
+_CONTEXT_TYPE_GUILD: int = 0
+_CONTEXT_TYPE_DM_CHANNEL: int = 1
+_CONTEXT_TYPE_PRIVATE_CHANNEL: int = 2
+
+
python:S1845 - Rename method "identify" to prevent any misunderstanding/clash with field "IDENTIFY" defined on line 300 • BLOCKERView issue

Location: discord/gateway.py:440

Why is this an issue?

Looking at the set of methods and fields in a class and finding two that differ only by capitalization is confusing to users of the class.

What changed

Renames the class field IDENTIFY to IDENTIFY_OP, which resolves the naming clash between the field IDENTIFY (line 300) and the method identify (line 440) that differed only by capitalization. By changing the field name to IDENTIFY_OP, the field and method names are no longer confusingly similar.

--- a/discord/gateway.py
+++ b/discord/gateway.py
@@ -300,1 +300,1 @@ class DiscordWebSocket:
-    IDENTIFY           = 2
+    IDENTIFY_OP        = 2
python:S1845 - Rename method "resume" to prevent any misunderstanding/clash with field "RESUME" defined on line 304 • BLOCKERView issue

Location: discord/gateway.py:475

Why is this an issue?

Looking at the set of methods and fields in a class and finding two that differ only by capitalization is confusing to users of the class.

What changed

Renames the class field RESUME to OP_RESUME, which resolves the naming clash between the field RESUME (line 304) and the method resume (line 475) that differed only by capitalization. By changing the field name to OP_RESUME, the field and method names are no longer confusingly similar.

--- a/discord/gateway.py
+++ b/discord/gateway.py
@@ -304,1 +304,1 @@ class DiscordWebSocket:
-    RESUME             = 6
+    OP_RESUME          = 6

Have a suggestion or found an issue? Share your feedback here.


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZUnUZllU1G2OajCqWpp for python:S1845 rule
- AZUnUZllU1G2OajCqWpo for python:S1845 rule
- AZUnUZjWU1G2OajCqWpC for python:S1845 rule
- AZUnUZjWU1G2OajCqWpE for python:S1845 rule
- AZUnUZjWU1G2OajCqWpG for python:S1845 rule

Generated by SonarQube Agent (task: 9b03ae5e-8408-4403-a343-d4cd7dcde75b)
@sonarqube-agent

Copy link
Copy Markdown
Author

⚠️ This repository does not have a CODEOWNERS file. The PR has been created but has not been automatically assigned to any reviewer. To ensure PRs are reviewed promptly, consider adding a CODEOWNERS file to your repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant