Skip to content

Conversation

Copy link

Copilot AI commented Nov 7, 2025

InvalidArgument duplicated behavior already provided by Python's TypeError and ValueError, adding unnecessary API surface and diverging from Python conventions.

Changes

  • Removed InvalidArgument class from errors.py and __all__ exports
  • Replaced 107 raise InvalidArgument statements with:
    • TypeError (34 cases) - for type mismatches (e.g., isinstance checks)
    • ValueError (73 cases) - for invalid values with correct types (e.g., range checks, conflicting parameters)
  • Updated imports across 18 files to remove InvalidArgument references
  • Updated docstrings to specify TypeError or ValueError instead of generic InvalidArgument

Migration

Before:

if not isinstance(perm, PermissionOverwrite):
    raise InvalidArgument(f"Expected PermissionOverwrite received {perm.__class__.__name__}")

if position <= 0:
    raise InvalidArgument("Cannot move role to position 0 or below")

After:

if not isinstance(perm, PermissionOverwrite):
    raise TypeError(f"Expected PermissionOverwrite received {perm.__class__.__name__}")

if position <= 0:
    raise ValueError("Cannot move role to position 0 or below")

Net reduction of 22 lines while improving semantic clarity and Python standards compliance.

Original prompt

This section details on the original issue you should resolve

<issue_title>Remove InvalidArgument infavour of builtin TypeError & ValueError</issue_title>
<issue_description>InvalidArgument currently duplicates behavior that is already covered by the built-in exceptions TypeError and ValueError. In most cases across the codebase, the situations where InvalidArgument is raised are either:

  • Incorrect types → should be TypeError
  • Incorrect values (but correct type) → should be ValueError

Because Python already provides a clear semantic split here, InvalidArgument adds no meaningful benefit and instead introduces inconsistency in error patterns across the library.

Proposal

  • Remove InvalidArgument
  • Replace existing uses with the appropriate built-in exception (TypeError or ValueError depending on context)
  • Update documentation and type hints accordingly

Benefits

  • Aligns with standard Python exception semantics
  • Improves clarity for users handling exceptions
  • Reduces surface area of the public API
    </issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@pycord-app
Copy link

pycord-app bot commented Nov 7, 2025

Thanks for opening this pull request!
Please make sure you have read the Contributing Guidelines and Code of Conduct.

This pull request can be checked-out with:

git fetch origin pull/187/head:pr-187
git checkout pr-187

This pull request can be installed with:

pip install git+https://github.com/Pycord-Development/pycord-next@refs/pull/187/head

@Soheab
Copy link

Soheab commented Nov 7, 2025

Holy I didn't expect it to do this

@Paillat-dev
Copy link
Member

Lok

Copilot AI and others added 2 commits November 7, 2025 18:59
- Replaced all 107 raise InvalidArgument statements with appropriate built-in exceptions
- Removed InvalidArgument class from errors.py
- Removed InvalidArgument from __all__ export
- Updated all imports to remove InvalidArgument
- Updated all docstrings referencing InvalidArgument
- Fixed except clause in http.py to catch ValueError instead

Co-authored-by: Soheab <33902984+Soheab@users.noreply.github.com>
Co-authored-by: Soheab <33902984+Soheab@users.noreply.github.com>
@read-the-docs-community
Copy link

read-the-docs-community bot commented Nov 7, 2025

Documentation build overview

📚 pycord-next | 🛠️ Build #30242042 | 📁 Comparing d47bfbc against latest (cd7ab41)


🔍 Preview build

Show files changed (32 files in total): 📝 32 modified | ➕ 0 added | ➖ 0 deleted
File Status
genindex.html 📝 modified
api/abcs.html 📝 modified
api/application_commands.html 📝 modified
api/clients.html 📝 modified
api/data_classes.html 📝 modified
api/exceptions.html 📝 modified
api/models.html 📝 modified
api/webhooks.html 📝 modified
_modules/discord/abc.html 📝 modified
_modules/discord/asset.html 📝 modified
_modules/discord/channel.html 📝 modified
_modules/discord/client.html 📝 modified
_modules/discord/errors.html 📝 modified
_modules/discord/guild.html 📝 modified
_modules/discord/integrations.html 📝 modified
_modules/discord/interactions.html 📝 modified
_modules/discord/member.html 📝 modified
_modules/discord/message.html 📝 modified
_modules/discord/partial_emoji.html 📝 modified
_modules/discord/reaction.html 📝 modified
_modules/discord/role.html 📝 modified
_modules/discord/scheduled_events.html 📝 modified
_modules/discord/shard.html 📝 modified
_modules/discord/stage_instance.html 📝 modified
_modules/discord/template.html 📝 modified
_modules/discord/user.html 📝 modified
ext/commands/api.html 📝 modified
_modules/discord/commands/core.html 📝 modified
_modules/discord/ui/select.html 📝 modified
modules/discord/webhook/async.html 📝 modified
_modules/discord/webhook/sync.html 📝 modified
_modules/discord/ext/pages/pagination.html 📝 modified

- Make docstrings more precise about when TypeError vs ValueError is raised
- Update stage_instance.py, template.py, shard.py, reaction.py, webhook/async_.py
- Address code review feedback for better developer guidance

Co-authored-by: Soheab <33902984+Soheab@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove InvalidArgument in favor of built-in TypeError and ValueError Remove InvalidArgument exception in favor of built-in TypeError and ValueError Nov 7, 2025
Copilot finished work on behalf of Soheab November 7, 2025 19:07
Copilot AI requested a review from Soheab November 7, 2025 19:07
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.

Remove InvalidArgument infavour of builtin TypeError & ValueError

3 participants