Skip to content

Conversation

@pangpang20
Copy link
Collaborator

Description

The internal type matcher in Faker previously treated None as invalid when the expected string value (want) was an empty string ("") or None. This led to false assertion failures for nullable or optional string fields, which is a common pattern in JSON Schema/OpenAPI schemas.

This change makes the str branch consistent with the existing bytes handling: when the expected value is "" or None, both "" and None are accepted as valid matches.

Changes Made

  • Updated the string type assertion logic in tests/fix_faker.py
  • Modified the spec == str branch in match_any to accept got == "" or got is None whenever want == "" or want is None
  • Kept strict equality checks for all other cases

Testing

  • Full Faker test suite passes
  • Verified correct behavior for nullable string fields and providers that may return empty strings
  • Confirmed no regression on bytes, bytearray, or memoryview handling
  • Manually tested edge cases: want="", want=None, and non-empty strings

@5xuanwen 5xuanwen merged commit 03883dc into HuaweiCloudDeveloper:master Nov 24, 2025
4 checks passed
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.

2 participants