Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Add NotImplementedError, reduce reliance on MethodError in Base #51873

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

BioTurboNick
Copy link
Contributor

@BioTurboNick BioTurboNick commented Oct 25, 2023

Following on from @Seelengrab 's suggestion in #50196 and my comment, I whipped up an implementation of it, also moving a subset of MethodErrors thrown from placeholder methods to this new NotImplementedError.

The error shares some code with MethodError, except where MethodError indicates a failure of dispatch, NotImplementedError indicates that dispatch succeeded, but either that a more specific implementation is expected and required.

NotImplementedError()
NotImplementedError(msg)
NotImplementedError(f, args)
NotImplementedError(f, args, msg)
NotImplementedError(f, args, interfacetype)
NotImplementedError(f, args, interfacetype, msg)

ERROR: NotImplementedError: no implementation has been provided matching f(::Type1, ::Type2), expected as part of the interface for <type here>. <msg here>

As part of this draft PR, I've started moving instances of Base using MethodError for non-dispatch failures, with the following understanding (a few I was unsure of):

  • MethodError: Function exists but method dispatch failed. Developer should check agreement of method signatures, or user should check number and subtype of arguments.
  • NotImplementedError: Dispatch succeeded, but the function indicates that it could be but hasn't yet been implemented for these types. Developer needs to implement it or user needs to define a method with types more specific than the one that was called to fix this. (e.g., convert)
  • ArgumentError: Dispatch succeeded, but the function expects the call should never work. (e.g., zero(Any))

There will be a lot of documentation to change around this if it's accepted.

@brenhinkeller brenhinkeller added the error handling Handling of exceptions by Julia or the user label Oct 26, 2023
@vtjnash
Copy link
Member

vtjnash commented Jan 31, 2024

Implements #7512

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error handling Handling of exceptions by Julia or the user
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants