Skip to content

MAINT: handle not implemented arguments centrally, via a dedicated annotation #114

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

Merged
merged 4 commits into from
Apr 17, 2023

Conversation

ev-br
Copy link
Collaborator

@ev-br ev-br commented Apr 16, 2023

as discussed in #112 (comment)

This does seem to gain a marginal LOC reduction and some possible readability improvement. Two points:

  • I'm {ab,re}using the NotImplemented singleton as the annotation. Introducing a new NotImplementedType is a bit awkward since typing.NotImplementedType is a thing from python 3.10, and we need to cover 3.8+. A simple alternative is to just use type(NotImplemented) instead of NotImplemented. Don't have a firm opinion, am open to suggestions.

  • NumPy uses a weird _NoValue sentinel in some cases; we mimicked it by defining an alias NoValue = None. In our usage we typically raise NotImplementedError on things with the NoValue default. Now that we have a dedicated annotation, NoValue alias seems extraneous. Anyone sees a need for it?

@ev-br ev-br requested a review from lezcano April 16, 2023 20:15
Base automatically changed from string_annot to main April 17, 2023 08:10
…tation

{ab,re}use NotImplemented singleton as the annotation.
@ev-br ev-br force-pushed the notimpl_annotation branch from 0dfeb24 to 64213f7 Compare April 17, 2023 08:12
@ev-br ev-br mentioned this pull request Apr 17, 2023
Merged
Copy link
Collaborator

@lezcano lezcano left a comment

Choose a reason for hiding this comment

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

I really like this! It really shows that, either you should be processing an arg in the implementation, or you should mark it as NotImplemented, so there's no ambiguity for "did you forget to use this arg, or is it just not implemented?"

About the _NoValue, it makes sense to remove it and simply replace it by None.

About the NotImplementedType, I'd say it's best to have the usual pattern of

try:
  from typing import NotImplementedType
except ImportError:
  NotImplementedType = typing.TypeVar("NotImplementedType")

The reason is that NotImplemented is an object, not a class, so using it for typing is a bit odd. WDYT?

Copy link
Collaborator

@lezcano lezcano left a comment

Choose a reason for hiding this comment

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

Great, thank you!

@ev-br ev-br merged commit 9250124 into main Apr 17, 2023
@ev-br ev-br deleted the notimpl_annotation branch April 17, 2023 12:19
@lezcano lezcano mentioned this pull request Apr 18, 2023
1 task
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.

2 participants