Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
Weak warning for a parameter not used but needed with Fast API

I use a custom exception handler with Fast API:

class CustomException(Exception):
    def __init__(self, err_message: str):
        self.err_message = err_message

@app.exception_handler(CustomException)
async def custom_exception_handler(request: Request, exc: CustomException):
    return JSONResponse(content={"error": exc.err_message})

Pycharm put the 'request: Request' as a weak warning:

''Parameter 'request' value is not used'' since it's not used in the code.

However, if I remove the parameter, I get a Fast API error when running the code. So I wonder if this is a PyCharm 'bug', if we can call it that way ?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

TL;DR: You use the _ as a replacement of the name or a prefix

Answer:

For that you don't disable the warning as suggest in the comments, it's is considered a bad practice to disable warnings because they exist for a reason. A better approach is to do some root cause analysis understand the warning by googling why and find a proper code change that removes it.

Working with linters in general some times it will be possible to think that there is no way to fix a warning or a suggestion other than causing another one to pop up. But you are getting there: you have to pick a solution that enhances code readability and maintainability without breaking any more rules or the actual software

In general in python there are some methods that will require parameters even if you don't use it because the above infrastructure using them is expecting to recieve a method with a certain signature template. For example when defining serverless lambda functions it is expected to have a eventand a context but you might as well not have any relevant information in the incoming event or the execution context to use.

You have to learn how to discard parameters while keeping them. For that you use the _ as a replacement of the name or a prefix

def lambda_example(event, context):
    """This raises a warning ⚠️"""
    print(event)


def second_example(event,_):
    """This does not ✔️"""
    print(event)


def third_example(_event,_context):
    """This does not either ✔️"""
    print("this does not care about it's parameters")
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda