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

Multiplying a measure by itself without specifying the measurement attribute results in TypeError #40

Closed
JackAtOmenApps opened this issue Apr 18, 2020 · 1 comment
Assignees
Labels

Comments

@JackAtOmenApps
Copy link
Collaborator

JackAtOmenApps commented Apr 18, 2020

>>> from measurement.measures import Mass
>>> m = Mass(lb=135)
>>> print(m)
135 lb
>>> print(m*m)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/runner/.local/share/virtualenvs/python3/lib/python3.8/site-packages/measurement/base.py", line 346, in __mul__
    return type(self)(value=value, unit=self.unit.org_name)
  File "/home/runner/.local/share/virtualenvs/python3/lib/python3.8/site-packages/measurement/base.py", line 254, in __init__
    value = decimal.Decimal(value)
TypeError: conversion from Mass to Decimal is not supported

It seems like this should work and return 135 lb * 135 lb = 18,225 lb

@codingjoe codingjoe added the bug label Apr 18, 2020
@codingjoe codingjoe self-assigned this Apr 18, 2020
@codingjoe
Copy link
Collaborator

@OmenApps good catch. However, I do believe this should raise an error. Since you can't multiply two masses (at least I don't know a unit for that). So what you can do is multiply a mass by a number. That should work and returns a multiple of that mass.
That being said, the error message is really misleading and an error should be raised differently.
Thanks for all the help, I will create a patch for this.

codingjoe added a commit that referenced this issue Apr 18, 2020
If two measures are multiplied that are not compatible – should
not be multipled, like mass x mass -, the error message should
indicate that incompatibility.
codingjoe added a commit that referenced this issue Apr 18, 2020
If two measures are multiplied that are not compatible – should
not be multipled, like mass x mass -, the error message should
indicate that incompatibility.
codingjoe added a commit that referenced this issue Apr 18, 2020
If two measures are multiplied that are not compatible – should
not be multipled, like mass x mass -, the error message should
indicate that incompatibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants