Skip to main content
added 3 characters in body
Source Link
Carcigenicate
  • 16.6k
  • 3
  • 37
  • 82

I have no experience with any of these libraries, so I can only comment on aspects of the language itself.


def insert_data():
    if not db:
        raise Exception('db object not defined')

Just to be clear, if db truly hasn't been assigned at this point, you cannot use if not db to check for that. Attempting to use a name before it's been associated with an object with raise a NameError, which you'd need to catch. At that point though, I'd probably just allow the original NameError to propagate and not worry about catching it unless there was other specific information that I wanted to add to the error.

If you meant that "db is in a bad, falsey state", I'd probably change the error message to be clearer what the problem is, and change raise Exception(. . . to raise ValueError(. . .. Throwing generic Exceptions isisn't a great idea, since it makes it harder for the caller of the function to handle only specific errors.


if us.header_key and request.headers.get('X-Purpleair') == us.header_key:
    db.insert_sensor_row(request.json)
elif not us.header_key:
    db.insert_sensor_row(request.json)

It seems like this could be reduced down to:

if not us.header_key or request.headers.get('X-Purpleair') == us.header_key:
    db.insert_sensor_row(request.json)

If not us.header_key is false, the right operand of or will run, and you know at that point that us.header_key must be truthy.


def displayCustomDateRangePicker(standardDate):
    if standardDate == 'custom':
        return False

    return True

This can be just:

def displayCustomDateRangePicker(standardDate):
    return standardDate != 'custom'

Please using "snake_case" naming when naming function and variables.



Sorry, I'm more tired than I originally thought. Hopefully someone else can give you a more complete review.

I have no experience with any of these libraries, so I can only comment on aspects of the language itself.


def insert_data():
    if not db:
        raise Exception('db object not defined')

Just to be clear, if db truly hasn't been assigned at this point, you cannot use if not db to check for that. Attempting to use a name before it's been associated with an object with raise a NameError, which you'd need to catch. At that point though, I'd probably just allow the original NameError to propagate and not worry about catching it unless there was other specific information that I wanted to add to the error.

If you meant that "db is in a bad, falsey state", I'd probably change the error message to be clearer what the problem is, and change raise Exception(. . . to raise ValueError(. . .. Throwing generic Exceptions is a great idea, since it makes it harder for the caller of the function to handle only specific errors.


if us.header_key and request.headers.get('X-Purpleair') == us.header_key:
    db.insert_sensor_row(request.json)
elif not us.header_key:
    db.insert_sensor_row(request.json)

It seems like this could be reduced down to:

if not us.header_key or request.headers.get('X-Purpleair') == us.header_key:
    db.insert_sensor_row(request.json)

If not us.header_key is false, the right operand of or will run, and you know at that point that us.header_key must be truthy.


def displayCustomDateRangePicker(standardDate):
    if standardDate == 'custom':
        return False

    return True

This can be just:

def displayCustomDateRangePicker(standardDate):
    return standardDate != 'custom'

Please using "snake_case" naming when naming function and variables.



Sorry, I'm more tired than I originally thought. Hopefully someone else can give you a more complete review.

I have no experience with any of these libraries, so I can only comment on aspects of the language itself.


def insert_data():
    if not db:
        raise Exception('db object not defined')

Just to be clear, if db truly hasn't been assigned at this point, you cannot use if not db to check for that. Attempting to use a name before it's been associated with an object with raise a NameError, which you'd need to catch. At that point though, I'd probably just allow the original NameError to propagate and not worry about catching it unless there was other specific information that I wanted to add to the error.

If you meant that "db is in a bad, falsey state", I'd probably change the error message to be clearer what the problem is, and change raise Exception(. . . to raise ValueError(. . .. Throwing generic Exceptions isn't a great idea, since it makes it harder for the caller of the function to handle only specific errors.


if us.header_key and request.headers.get('X-Purpleair') == us.header_key:
    db.insert_sensor_row(request.json)
elif not us.header_key:
    db.insert_sensor_row(request.json)

It seems like this could be reduced down to:

if not us.header_key or request.headers.get('X-Purpleair') == us.header_key:
    db.insert_sensor_row(request.json)

If not us.header_key is false, the right operand of or will run, and you know at that point that us.header_key must be truthy.


def displayCustomDateRangePicker(standardDate):
    if standardDate == 'custom':
        return False

    return True

This can be just:

def displayCustomDateRangePicker(standardDate):
    return standardDate != 'custom'

Please using "snake_case" naming when naming function and variables.



Sorry, I'm more tired than I originally thought. Hopefully someone else can give you a more complete review.

Source Link
Carcigenicate
  • 16.6k
  • 3
  • 37
  • 82

I have no experience with any of these libraries, so I can only comment on aspects of the language itself.


def insert_data():
    if not db:
        raise Exception('db object not defined')

Just to be clear, if db truly hasn't been assigned at this point, you cannot use if not db to check for that. Attempting to use a name before it's been associated with an object with raise a NameError, which you'd need to catch. At that point though, I'd probably just allow the original NameError to propagate and not worry about catching it unless there was other specific information that I wanted to add to the error.

If you meant that "db is in a bad, falsey state", I'd probably change the error message to be clearer what the problem is, and change raise Exception(. . . to raise ValueError(. . .. Throwing generic Exceptions is a great idea, since it makes it harder for the caller of the function to handle only specific errors.


if us.header_key and request.headers.get('X-Purpleair') == us.header_key:
    db.insert_sensor_row(request.json)
elif not us.header_key:
    db.insert_sensor_row(request.json)

It seems like this could be reduced down to:

if not us.header_key or request.headers.get('X-Purpleair') == us.header_key:
    db.insert_sensor_row(request.json)

If not us.header_key is false, the right operand of or will run, and you know at that point that us.header_key must be truthy.


def displayCustomDateRangePicker(standardDate):
    if standardDate == 'custom':
        return False

    return True

This can be just:

def displayCustomDateRangePicker(standardDate):
    return standardDate != 'custom'

Please using "snake_case" naming when naming function and variables.



Sorry, I'm more tired than I originally thought. Hopefully someone else can give you a more complete review.