fix(pt_BR): allow repeated digits in numeric CNPJ roots - #2446
Open
liuyaohui666 wants to merge 1 commit into
Open
fix(pt_BR): allow repeated digits in numeric CNPJ roots#2446liuyaohui666 wants to merge 1 commit into
liuyaohui666 wants to merge 1 commit into
Conversation
liuyaohui666
marked this pull request as ready for review
August 21, 2026 13:02
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this change
Numeric Brazilian CNPJ generation now samples the eight root digits with replacement. A regression test uses the Receita Federal example
18.781.203/0001-28to prove that repeated root digits are supported while preserving checksum generation.What was wrong
_company_id_base(False)usedrandom_sample(range(10), 8), which samples without replacement. That made every generated eight-digit root contain eight distinct digits, although valid numeric CNPJs may repeat digits.As a result, Faker could generate only
10P8 = 1,814,400roots out of the10^8 = 100,000,000possible numeric roots (about 1.8%).How this fixes it
Use
random_choices(range(10), length=8)so each root position is sampled independently. The alphanumeric path, branch suffix, public API, and checksum calculation remain unchanged.Fixes #2445
Verification
pytest tests/providers/test_company.py -q: 93 passedtox -e py -- tests/providers/test_company.py: 93 passed, then 101 passed in the locale module rungit diff --checkpassedAI Assistance Disclosure (REQUIRED)
OpenAI Codex (GPT-5) assisted with repository/source-history inspection, duplicate searching, the reproducer, the regression test, the one-line implementation, and drafting this PR. I reviewed the diff and ran the listed tests and static checks locally.
Checklist
make lint.makeis unavailable in the Windows development environment. Its Black, isort, flake8, and mypy components were run individually and passed; the complete GitHub Actions matrix is left to verify the repository-native workflow.