1
0
mirror of https://github.com/ilri/dspace-statistics-api.git synced 2025-05-08 14:16:01 +02:00

Move all imports to top of file

A few months ago I had an issue setting up mocking because I was
trying to be clever importing these libraries only when I needed
them rather than at the global scope. Someone pointed out to me
that if the imports are at the top of the file Falcon will load
them once when the WSGI server starts, whereas if they are in the
on_get() or on_post() they will load for every request! Also, it
seems that PEP8 recommends keeping imports at the top of the file
anyways, so I will just do that.

Imports sorted with isort.

See: https://www.python.org/dev/peps/pep-0008/#imports
This commit is contained in:
2020-12-18 22:42:06 +02:00
parent a0d0a47150
commit 4dbf734a4b
3 changed files with 9 additions and 11 deletions

View File

@ -1,4 +1,5 @@
import falcon
import psycopg2.extras
from .database import DatabaseManager
from .items import get_downloads, get_views
@ -120,8 +121,6 @@ class ItemResource:
def on_get(self, req, resp, item_id):
"""Handles GET requests"""
import psycopg2.extras
# Adapt Pythons uuid.UUID type to PostgreSQLs uuid
# See: https://www.psycopg.org/docs/extras.html
psycopg2.extras.register_uuid()