fix: replace unsafe 'is' comparisons with '==' for strings#201
Open
MuriloM676 wants to merge 2 commits intofazedordecodigo:developfrom
Open
fix: replace unsafe 'is' comparisons with '==' for strings#201MuriloM676 wants to merge 2 commits intofazedordecodigo:developfrom
MuriloM676 wants to merge 2 commits intofazedordecodigo:developfrom
Conversation
added 2 commits
February 2, 2026 14:21
Fixes fazedordecodigo#192 Changed all string comparisons from identity checks (is) to equality checks (==) across validation contracts. The 'is' operator checks object identity in memory, while '==' checks value equality, which is the correct approach for comparing string constants. Files modified: - bool_validation_contract.py - brazilian_document_validation_contract.py - collections_validation_contract.py - commons_validation_contract.py - contract.py - credit_card_validation_contract.py - email_validation_contract.py - strings_validation_contract.py - url_validation_contract.py Total: 23 occurrences corrected across 9 files.
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.
Descrição
Este PR corrige o issue #192, substituindo todas as comparações inseguras de strings que utilizam o operador
ispelo operador==nos contratos de validação.O problema: O operador
isverifica identidade de objeto (se dois objetos são o mesmo na memória), enquanto==verifica igualdade de valores. Para comparações de strings, especialmente constantes, devemos usar==pois o comportamento deiscom strings pode ser imprevisível devido ao string interning do Python.Mudanças Propostas
message is CONSTANTpormessage == CONSTANTem 9 arquivos de contratos de validaçãobool_validation_contract.py,brazilian_document_validation_contract.py,collections_validation_contract.py,commons_validation_contract.py,contract.py,credit_card_validation_contract.py,email_validation_contract.py,strings_validation_contract.py,url_validation_contract.pyChecklist de Revisão
Comentários Adicionais
Esta é uma correção importante de segurança e boas práticas. Embora o código atual provavelmente funcione devido ao string interning do Python para literais, usar
ispara comparar strings é considerado uma má prática e pode levar a bugs sutis e difíceis de debugar em cenários específicos.A correção é backward-compatible e não altera o comportamento funcional da biblioteca - apenas torna o código mais robusto e seguro.
Issue Relacionada
Fixes #192