Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!