Skip to content

Conversation

@davidhewitt
Copy link
Contributor

Change Summary

In advance of fixing #1856, I wanted to set up standard machinery for formatting Python objects to strings by calling str(), this is all the IP address serialization will do.

  • First commit implements that refactoring.
  • Second commit enables clippy::match_same_arms lint which encourages us to deduplicate some code.

Related issue number

N/A

Checklist

  • Unit tests for the changes exist
  • Documentation reflects the changes where applicable
  • Pydantic tests pass with this pydantic-core (except for expected changes)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

@davidhewitt davidhewitt requested a review from Viicos October 29, 2025 15:53
ObType::Generator => self.generator_object.as_ptr() as usize == ob_type,
ObType::Path => self.path_object.as_ptr() as usize == ob_type,
ObType::Pattern => self.path_object.as_ptr() as usize == ob_type,
ObType::Pattern => self.pattern_object.as_ptr() as usize == ob_type,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Clippy caught a legitimate typo here, I'm not sure if it's actually observable in practice though.

let py_url: PyMultiHostUrl = value.extract()?;
py_url.__str__(py).into_py_any(py)?
}
ObType::Url | ObType::MultiHostUrl | ObType::Path => serialize_via_str(value, serialize_to_python())?,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

e.g. IPAddress pathway will be added here

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 29, 2025

CodSpeed Performance Report

Merging #1867 will degrade performances by 11.62%

Comparing dh/to-str-logic (0d60f15) with main (1660728)

Summary

❌ 1 regression
✅ 162 untouched

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
test_set_of_ints_core_json_duplicates 381.7 µs 431.8 µs -11.62%

@davidhewitt davidhewitt merged commit 4d4975a into main Oct 29, 2025
31 of 32 checks passed
@davidhewitt davidhewitt deleted the dh/to-str-logic branch October 29, 2025 17:36
davidhewitt added a commit to pydantic/pydantic that referenced this pull request Nov 5, 2025
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.

3 participants