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

feat(bindings/python): Add repr for metadata #5783

Merged
merged 7 commits into from
Mar 18, 2025

Conversation

yihong0618
Copy link
Contributor

… better print and debug

Which issue does this PR close?

Closes #5768

Copy link
Member

@Zheaoli Zheaoli left a comment

Choose a reason for hiding this comment

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

Would you mind adding unit test here. I think some simple assert is enough

@yihong0618
Copy link
Contributor Author

Would you mind adding unit test here. I think some simple assert is enough

Thanks and Done

@yihong0618 yihong0618 requested a review from Zheaoli March 17, 2025 01:02

pub fn __repr__(&self) -> String {
format!(
"Metadata(content_disposition={}, content_length={}, content_md5={}, content_type={}, etag={}, mode={})",
Copy link
Member

Choose a reason for hiding this comment

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

content_disposition might be empty most of the time, so I don't think it's worth printing in repr. How about this instead:

"Metadata(mode={}, content_length={}, content_type={}, etag={})"

We arrange the metadata by importance and ignore less frequently used metadata.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool will drop this, you are right.

and FYI last_modified maybe needed here too?

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool will update this patch after last_modified Done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done and lerned that, thanks

Comment on lines 103 to 113
let rfc3339 = dt.to_rfc3339_opts(SecondsFormat::Micros, false);
if let Some(pos) = rfc3339.find('.') {
let (base, tz) = rfc3339.split_at(pos + 1);
let tz_pos = tz.find('+').or_else(|| tz.find('-')).unwrap_or(tz.len());
let (micros, tz_suffix) = tz.split_at(tz_pos);

let micros = format!("{:0<6}", micros);
format!("{}{}{}", base, micros, tz_suffix)
} else {
rfc3339
}
Copy link
Member

Choose a reason for hiding this comment

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

Print last_modified in this way doesn't look good to me.

If we have a clear target format, maybe we can use DateTime::format instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will learn that

};

format!(
"Metadata(content_length={}, content_md5={}, content_type={}, etag={}, mode={}, last_modified={})",
Copy link
Member

Choose a reason for hiding this comment

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

I believe mode is the most important metadata, and content_md5 can be removed since we don't encourage users to rely on it.

So the final list will be:

  • mode
  • content_length
  • content_type
  • last_modified
  • etag

Copy link
Contributor Author

Choose a reason for hiding this comment

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

copy

Signed-off-by: yihong0618 <[email protected]>
@Xuanwo
Copy link
Member

Xuanwo commented Mar 17, 2025

This is not a breaking change, right? I'm guessing we don't need the ! in PR title.

@yihong0618 yihong0618 changed the title refactor(bindings/python)!: add repr for meta for python bindings for… refactor(bindings/python): add repr for meta for python bindings for… Mar 17, 2025
@yihong0618
Copy link
Contributor Author

This is not a breaking change, right? I'm guessing we don't need the ! in PR title.

OK, and FYI, it kind of small change the behaviour of print...

@Xuanwo
Copy link
Member

Xuanwo commented Mar 17, 2025

OK, and FYI, it kind of small change the behaviour of print...

I'm not familiar with python. Does python ecosystem treat such changes as breaking changes?

@yihong0618
Copy link
Contributor Author

yihong0618 commented Mar 17, 2025

OK, and FYI, it kind of small change the behaviour of print...

I'm not familiar with python. Does python ecosystem treat such changes as breaking changes?

if user depend the repr maybe break them, but I think its fine since we do not have repr before

@Xuanwo Xuanwo changed the title refactor(bindings/python): add repr for meta for python bindings for… feat(bindings/python): Add repr for metadata Mar 18, 2025
Copy link
Member

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

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

Thank you @yihong0618 for this work!

@Xuanwo Xuanwo dismissed Zheaoli’s stale review March 18, 2025 01:46

Tests added.

@Xuanwo Xuanwo merged commit bc19998 into apache:main Mar 18, 2025
64 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add __repr__ or __str__ to meta in python binding
3 participants