Skip to content

Formatter instability: trailing clause comments in if statement #7602

@charliermarsh

Description

@charliermarsh

Given:

def Get_x_csrf_token(cookie, showErrors=bool):
    try:
        try:
            socket.create_connection(("google.com", 80))
        except socket.gaierror:
            if showErrors == True:
                raise APIConnectFailed(
                    "No internet connection, check your internet connection and try again."
                )
            else:
                return
            # req.urlopen('http://google.com')
            # print("No internet connection, quiting.")
            # exit(-1)
        # try:
        # except:
        xsrfRequest = requests.post(
            "https://auth.roblox.com/v2/logout", cookies={".ROBLOSECURITY": cookie}
        )
        if xsrfRequest.headers:
            if xsrfRequest.headers.get("x-csrf-token") == None:
                if showErrors == True:
                    raise InvalidCookie(
                        "Invalid .ROBLOSECURITY cookie, are you sure you're using your current cookie ?"
                    )
                else:
                    return
            else:
                return xsrfRequest.headers["x-csrf-token"]
        else:
            if showErrors == True:
                raise NoHeadersError(
                    "The API didn't return any response headers. Check your internet connection."
                )
            else:
                return
                # APIError("The request returned no result headers, Response: ",xsrfRequest.status_code)

            # else:
            # print(xsrfRequest.headers["x-csrf-token"],xsrfRequest.headers)

    except Exception as e:
        raise GetTokenException(
            f"'Get x-csrf-token' process returned an Exception: {e}'"
        )

We're removing the newline after # print(xsrfRequest.headers["x-csrf-token"],xsrfRequest.headers), which leads to an instability.

The above code is the once-formatted version of:

def Get_x_csrf_token(cookie,showErrors=bool):
    try:
        try:
            socket.create_connection(('google.com', 80))
        except socket.gaierror:
            if showErrors == True:
                raise APIConnectFailed("No internet connection, check your internet connection and try again.")
            else:
                return
        #try:
            #req.urlopen('http://google.com')
        #except:
            #print("No internet connection, quiting.")
            #exit(-1)
        xsrfRequest = requests.post("https://auth.roblox.com/v2/logout",
                                    cookies={".ROBLOSECURITY": cookie})
        if xsrfRequest.headers:

            if xsrfRequest.headers.get("x-csrf-token") == None:
                if showErrors == True:
                    raise InvalidCookie("Invalid .ROBLOSECURITY cookie, are you sure you're using your current cookie ?")
                else:
                    return
            else:
                return xsrfRequest.headers["x-csrf-token"]
        else:
            if showErrors == True:
                raise NoHeadersError("The API didn't return any response headers. Check your internet connection.")
            else:
                return


            #else:
                #APIError("The request returned no result headers, Response: ",xsrfRequest.status_code)
            #print(xsrfRequest.headers["x-csrf-token"],xsrfRequest.headers)

    except Exception as e:
        raise GetTokenException(f"'Get x-csrf-token' process returned an Exception: {e}'")

Sourced from #7590 (A_14230110707883433080.py).

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingformatterRelated to the formatter

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions