Skip to content

TASK: Add Measurement class (#18)#46

Open
P-r-e-m-i-u-m wants to merge 6 commits intoTheGittyPerson:mainfrom
P-r-e-m-i-u-m:feature/measurement-class
Open

TASK: Add Measurement class (#18)#46
P-r-e-m-i-u-m wants to merge 6 commits intoTheGittyPerson:mainfrom
P-r-e-m-i-u-m:feature/measurement-class

Conversation

@P-r-e-m-i-u-m
Copy link
Copy Markdown
Contributor

Closes #18

Added a Measurement class to store a value with a unit, and integrated it into Person.

Changes:

  • Added src/measurement.py with Measurement class
  • Supports units: m, cm, mm, ft, in
  • Includes to_metres(), to_unit(), describe(), and __eq__() methods
  • Updated Person.height type from float to Measurement | None
  • Added set_height() method to Person
  • Updated introduce() to use Measurement.describe()

@P-r-e-m-i-u-m P-r-e-m-i-u-m force-pushed the feature/measurement-class branch from 63c9ac2 to 5d6034d Compare March 15, 2026 16:33
@TheGittyPerson TheGittyPerson added feature New feature or enhancement task This is a task issue / PR completing a task labels Mar 16, 2026
@TheGittyPerson TheGittyPerson force-pushed the feature/measurement-class branch from 5d6034d to b046bdf Compare March 17, 2026 16:30
@TheGittyPerson
Copy link
Copy Markdown
Owner

I updated your branch with a rebase 👍

@TheGittyPerson
Copy link
Copy Markdown
Owner

@P-r-e-m-i-u-m I just left a comment for @Poorna-Chandra-D in #48, but if he's unable to respond within a day or two, you may incorporate aspects of his Measurement class into yours (also read my review comments to him). You can even do some copy-pasting if you want. If you do decide to do this, please make your changes, and i will update your branch for you and resolve conflicts.

@Poorna-Chandra-D
Copy link
Copy Markdown
Contributor

Poorna-Chandra-D commented Mar 27, 2026

@P-r-e-m-i-u-m confirmed from my side: you are welcome to reuse any relevant parts of my Measurement implementation and the review suggestions from #48 in this PR. I support #46 being the primary PR for this task.

@TheGittyPerson TheGittyPerson force-pushed the feature/measurement-class branch from 31f8abd to 42a8b41 Compare March 27, 2026 13:47
@TheGittyPerson
Copy link
Copy Markdown
Owner

Updated your branch with a rebase 👍 will be reviewing your new changes soon

@TheGittyPerson TheGittyPerson self-requested a review March 27, 2026 13:52
Copy link
Copy Markdown
Owner

@TheGittyPerson TheGittyPerson left a comment

Choose a reason for hiding this comment

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

Here are some more suggestions for improvement. Please do ask questions if you have any

Comment thread theperson/measurement.py Outdated
if unit not in VALID_UNITS:
raise ValueError(
f"'{unit}' is not a recognised unit. "
f"Valid units are: {', '.join(sorted(VALID_UNITS))}."
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

VALID_UNITS only includes the shortened units (m, cm, ft, ...) and not their canonical forms (meters, centimeters, feet, ...). Consider adding those to the outputted list or mention something about it somewhere in the error message.

Comment thread theperson/person.py
def set_height(self, value: float, unit: str = "m") -> None:
"""Set the person's height as a Measurement.

Args:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Consider moving this to the new Physical dataclass above

Comment thread theperson/measurement.py


@total_ordering
class Measurement:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

What do you think about renaming the class to Length or Distance as the class only covers physical lengths?

Also, to prove you're actually reading these review comments and are not using AI or anything, leave a comment under your PR addressing my idea. Also include the name of your favorite cartoon, TV show or movie. Sorry if this is a bit wierd, but I want to be completely sure, since you previously mentioned your code is completely written by yourself.

Comment thread theperson/measurement.py
}
return self.value * conversions[self.unit]

def to_unit(self, unit: str) -> "Measurement":
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Add a clean type check for unit

Comment thread theperson/measurement.py Outdated
"""Check equality by comparing values in metres."""
if not isinstance(other, Measurement):
return NotImplemented
return self.to_metres() == other.to_metres()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

In Poorna's PR I did say to use exact comparison, but now that I think about it, floating-point conversions between units can yield tiny differences and make logically equal values compare as unequal. If we expect comparisons across units, consider using math.isclose with a tolerance.

Comment thread theperson/measurement.py Outdated
Comment on lines +80 to +86
conversions = {
"m": 1.0,
"cm": 100.0,
"mm": 1000.0,
"ft": 3.28084,
"in": 39.3701,
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

You have this in both to_metres as well with slightly different constants. This is maintainability risk, so I recommend a single base map in metres and get the inverse when needed.

Comment thread theperson/measurement.py Outdated

def __str__(self) -> str:
"""Return a string representation of the measurement."""
return self.describe()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

describe() rounds to 2 decimal places. I'd say make formatting configurable (much better) or keep full precision for __str__ while describe() can use rounding.

Signed-off-by: 🄂ʏᴇᴅ 🄰ʙᴅᴜʟ 🄰ᴍᴀ🄝 ✧ <amanbaba9404522@gmail.com>

# Conflicts:
#	src/person.py

# Conflicts (second rebase conflict res):
#	theperson/measurement.py
#	theperson/person.py

# Conflicts (third rebase conflict res):
#	theperson/person.py
Signed-off-by: 🄂ʏᴇᴅ 🄰ʙᴅᴜʟ 🄰ᴍᴀ🄝 ✧ <amanbaba9404522@gmail.com>
@TheGittyPerson TheGittyPerson force-pushed the feature/measurement-class branch from 42a8b41 to 3d2acbf Compare March 29, 2026 11:17
@P-r-e-m-i-u-m
Copy link
Copy Markdown
Contributor Author

@TheGittyPerson! I feel like keeping it as Measurement makes more sense since it’s a general concept and could support things like weight or temperature later on. I’m also addressing all the review points below.
And my favorite show is God of War I guess the game series counts, right

@P-r-e-m-i-u-m
Copy link
Copy Markdown
Contributor Author

if you tell me i will fix the code ok

…nit type check

Signed-off-by: 🄂ʏᴇᴅ 🄰ʙᴅᴜʟ 🄰ᴍᴀ🄝 ✧ <amanbaba9404522@gmail.com>
@P-r-e-m-i-u-m
Copy link
Copy Markdown
Contributor Author

wait

Signed-off-by: 🄂ʏᴇᴅ 🄰ʙᴅᴜʟ 🄰ᴍᴀ🄝 ✧ <amanbaba9404522@gmail.com>
Signed-off-by: 🄂ʏᴇᴅ 🄰ʙᴅᴜʟ 🄰ᴍᴀ🄝 ✧ <amanbaba9404522@gmail.com>
Signed-off-by: 🄂ʏᴇᴅ 🄰ʙᴅᴜʟ 🄰ᴍᴀ🄝 ✧ <amanbaba9404522@gmail.com>
@P-r-e-m-i-u-m
Copy link
Copy Markdown
Contributor Author

It was tough bro 😅 but nice. That’s why you gave this to me, right?

@TheGittyPerson
Copy link
Copy Markdown
Owner

It was mostly because you asked for it but sure 🙌

@github-actions
Copy link
Copy Markdown

This pull request has been inactive for some time, and will therefore be marked as 'stale'.
Tag a maintainer if you wish to discuss this further.

@github-actions github-actions bot added the stale No activity here in a while label Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or enhancement stale No activity here in a while task This is a task issue / PR completing a task

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TASK: Add Measurement class

3 participants