Skip to content

Conversation

@adriangb
Copy link
Contributor

@adriangb adriangb commented Jul 8, 2023

No description provided.

@codecov-commenter
Copy link

codecov-commenter commented Jul 8, 2023

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.25%. Comparing base (85ad9b6) to head (2e71582).
Report is 22 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #43      +/-   ##
==========================================
+ Coverage   94.08%   94.25%   +0.17%     
==========================================
  Files           2        2              
  Lines         169      174       +5     
  Branches       27       27              
==========================================
+ Hits          159      164       +5     
  Misses          8        8              
  Partials        2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines -314 to +315
StrType = TypeVar("StrType", bound=str)
_StrType = TypeVar("_StrType", bound=str)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see any reason for us to export these type vars

Comment on lines +322 to +323
_NumericType = TypeVar('_NumericType', bound=Union[SupportsFloat, SupportsIndex])
IsFinite = Annotated[_NumericType, Predicate(math.isfinite)]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Others like IsNotNull are maybe a bit less valuable since the predicate function would have to be lambda x: not math.isnull(x) which can't be easily recognized.

Copy link
Member

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

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

Looks good! Should we document that math.isfinite is a useful specific predicate to recognise, or just leave that to implementors?

Hypothesis already has special support here, fwiw.

@adriangb
Copy link
Contributor Author

adriangb commented Jul 9, 2023

Yup this does need docs!

@adriangb adriangb merged commit 89d0321 into annotated-types:main Jul 9, 2023
@adriangb adriangb deleted the add-is-finite branch July 9, 2023 16:16
- `IsLower = Predicate(str.islower)`
- `IsUpper = Predicate(str.isupper)`
- `IsDigit = Predicate(str.isdigit)`
- `IsFinite = Predicate(math.isfinite)`
Copy link
Member

Choose a reason for hiding this comment

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

We document this as if we're just defining the annotation, but actually define the annotated type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, I kept the existing format, but I'm not sure if that was an affirmation, question, or suggestion?

Copy link
Member

Choose a reason for hiding this comment

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

More of a thoughtless observation, really 😓

Coming back with some more thought, I'm concerned that we're misleading people a bit with the docs - as written, I would expect to write Annotated[float, IsFinite] rather than IsFinite[float] - but my understanding is that the latter is actually required given our implementation so far, right? If so, I think we should change the docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, or we can just change the = to : and put an example there:

- `IsFinite`: `Predicate(math.isfinite)`

These predicates are used as `x: IsFinite[float]` which is equivalent to `x: Annotated[float, Predicate(math.isfinite)]` (that is, `IsFinite` is just a generic type alias for your convenience).

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.

3 participants