This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
validate-docbr is a Python package for validating and
generating Brazilian documents (CPF, CNPJ, CNH, CNS, PIS,
Título Eleitoral, RENAVAM, Certidão). Published on PyPI as
validate-docbr, version 2.0.0.
- Code (class names, method names, variables): English
- Comments, docstrings, docs, commits, issues: pt-BR
- Claude files (CLAUDE.md, agents, commands): English
- Package manager: uv
(
pyproject.toml+uv.lock) - Type checker: ty
- Task runner: Task
(
Taskfile.yml) - Tests: pytest 9.0.2 + pytest-cov 7.1.0
- Python: >= 3.10 (tested 3.10–3.14)
task build # Build Docker image (installs git hooks)
task test # Run all tests with pytest
task test-coverage # Run tests with coverage (threshold 98%)
task type-check # Run ty type checker
task lint # Run all linters
task lint-fix # Auto-fix Python lint issues
task ci # Run lint + test-coverage
task shell # Open a bash shell in the containerTo run a single test:
uv run pytest tests/test_CPF.py
uv run pytest tests/test_CPF.py::TestCpf::test_maskEvery document type is a class inheriting from DocumentBase
(ABC in validate_docbr/DocumentBase.py).
DocumentBase defines the interface:
validate(doc)— abstract, validates a document stringgenerate(mask)— abstract, generates a valid documentmask(doc)— abstract, applies formatting maskvalidate_list,generate_list— concrete methods_only_digits,_validate_input— shared utilities
Unimplemented abstract methods raise
FunctionNotImplementedError
(defined in validate_docbr/exceptions.py).
Each document class (e.g., CPF.py, CNPJ.py) implements
the three abstract methods with document-specific validation
logic (check digits, length, masks). Imports use absolute
style: from validate_docbr.DocumentBase import DocumentBase.
generic.py provides validate_docs(), a standalone function
that validates heterogeneous document lists.
- Create a class in
validate_docbr/inheriting fromDocumentBase, named by the document's acronym - Implement
validate,generate, andmask - Export it in
validate_docbr/__init__.py - Add tests in
tests/test_<Name>.py(useunittestwith Given-When-Then pattern) - Run
task type-checkandtask test-coverage
- Type hints: modern generic syntax
(
list[str],str | None) — notypingimports (PEP 585) - Imports: absolute style
(
from validate_docbr.DocumentBase import DocumentBase) - Tests: Given-When-Then with
# Given,# When,# Thencomments - Type safety: code must pass
ty checkwith no errors
- Pre-push hook runs lint + test-coverage
(installed via
task build) - GitHub Actions (
ci.yml) runs lint then tests across Python 3.10–3.14 usinguv - Coverage must stay at or above 98.00%