Skip to content

Conversation

asmeurer
Copy link
Member

And other small fixes. The type hint fixes come from numpy/numpy#18585, except for the Literal change in qr which comes from me.

One thing that I didn't address here is the type for the stream argument in __dlpack__. See this discussion numpy/numpy#18585 (comment).

@rgommers rgommers added the topic: Static Typing Static typing. label Jul 17, 2021
Copy link
Contributor

@kgryte kgryte left a comment

Choose a reason for hiding this comment

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

LGTM.

@@ -19,7 +19,7 @@ Joins a sequence of arrays along an existing axis.

#### Parameters

- **arrays**: _Tuple\[ <array>, ... ]_
- **arrays**: _Union\[Tuple\[ <array>, ... ], List\[ <array> ] ]_
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make more sense to use Sequence, rather than a Union?

Copy link
Member Author

Choose a reason for hiding this comment

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

That was mentioned here numpy/numpy#18585 (comment). If we agree Sequence is better we can use that instead.

Copy link
Member

Choose a reason for hiding this comment

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

I am fairly happy with requiring a tuple or list. Sequence is quite broad (e.g. is an array a sequence?), and I'm not that interested in supporting such flexibility for custom containers, it ends up hurting more than helping often.

@@ -154,7 +154,7 @@ Joins a sequence of arrays along a new axis.

#### Parameters

- **arrays**: _Tuple\[ <array>, ... ]_
- **arrays**: _Union\[Tuple\[ <array>, ... ], List\[ <array> ] ]_
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above regarding Sequence.

@@ -57,7 +57,7 @@ Convert the input to an array.

#### Parameters

- **obj**: _Union\[ float, NestedSequence\[ bool | int | float ], SupportsDLPack, SupportsBufferProtocol ]_
- **obj**: _Union\[ <array>, float, NestedSequence\[ bool | int | float ], SupportsDLPack, SupportsBufferProtocol ]_
Copy link
Member

Choose a reason for hiding this comment

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

I can raise an issue/PR if more appropriate, but while you're at it—as the docs say obj can be a Python scalar, am I correct in saying that bool and int should be part of the top-level Union type hint alongside float?

Copy link
Member

Choose a reason for hiding this comment

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

Technically bool and int are already covered by float (they sub-types), so the main rule we have used for determining whether or not to add bool and/or int explicitly is: does it help for clarity?

In this case the output dtype is different for bool or int scalar input, so makes sense to add explicitly.

@asmeurer
Copy link
Member Author

Can this be merged? I'm not clear if we should be using Sequence or Union[Tuple,List].

@rgommers
Copy link
Member

Can this be merged? I'm not clear if we should be using Sequence or Union[Tuple,List].

Let's get this in since it's been pending for a while. If there is follow-up discussion on sequence vs list/tuple we can deal with it separately. Thanks @asmeurer, all.

@rgommers rgommers merged commit 30a317f into data-apis:main Aug 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: Static Typing Static typing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants