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

[Typing] Fix type stubs #220

Merged
merged 4 commits into from Dec 8, 2023
Merged

Conversation

n-takumasa
Copy link
Contributor

  • Fix default args: especially set_default_units()
  • Fix math operators: especially mul and div

NOTE

# master
# pip install git+https://github.com/python-quantities/python-quantities

from typing import reveal_type
import quantities as pq

distance = 42 * pq.metre
time = 17 * pq.second
velocity = distance / time
reveal_type(velocity)
# Static type: Type of "velocity" is "ndarray[Any, dtype[floating[_64Bit]]]"
# Runtime type is 'Quantity'

reveal_type(distance * 2)
# Static type: Type of "distance * 2" is "ndarray[Any, dtype[signedinteger[Any]]]"
# Runtime: ValueError

reveal_type(distance + 1)
# Static type: Type of "distance + 1" is "Quantity"
# this PR

from typing import reveal_type
import quantities as pq

distance = 42 * pq.metre
time = 17 * pq.second
velocity = distance / time
reveal_type(velocity)
# Static type: Type of "velocity" is "Quantity"
# Runtime type is 'Quantity'

reveal_type(distance * 2)
# Type of "distance * 2" is "Quantity"

reveal_type(distance + 1)
# Operator "+" not supported for types "Quantity" and "Literal[1]"

reveal_type(distance + time)  # should be error but cannot detect by static type now

@apdavison apdavison merged commit 4b6d3ef into python-quantities:master Dec 8, 2023
19 checks passed
@n-takumasa n-takumasa deleted the typing branch December 23, 2023 02:56
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.

None yet

2 participants