From 831aead60d13ad30fd21e0dd416e7582051cb332 Mon Sep 17 00:00:00 2001 From: vmagueta Date: Tue, 29 Oct 2024 10:23:08 -0300 Subject: [PATCH] =?UTF-8?q?Adicionada=20constante=20CPF=5FLENGHT=20para=20?= =?UTF-8?q?melhor=20leitura=20do=20c=C3=B3digo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- brutils/cpf.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/brutils/cpf.py b/brutils/cpf.py index 7376954d..5ccccd2e 100644 --- a/brutils/cpf.py +++ b/brutils/cpf.py @@ -271,13 +271,13 @@ def remove_symbols_cpf(cpf: str) -> str: >>> remove_symbols_cpf('000.111.222-333') None """ + CPF_LENGHT = 11 - result = None - cpf_no_symbols = "" - if isinstance(cpf, str) and cpf != "": - cpf_no_symbols = "".join([char for char in cpf if char not in ".-"]) + if not cpf: + return None - if len(cpf_no_symbols) == 11: - result = cpf_no_symbols + if isinstance(cpf, str) and cpf != "": + cpf_no_symbols = "".join([char for char in cpf if char.isalnum()]) - return result + if len(cpf_no_symbols) == CPF_LENGHT: + return cpf_no_symbols