Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

147
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda