Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correcting mypy errors and updating #236

Merged
merged 1 commit into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jsonschema = "==2.6.0"
markupsafe = "==1.0"
mccabe = "==0.6.1"
mock = "==2.0.0"
mypy = "==0.560"
mypy = "==0.670"
"nose2" = "==0.7.3"
pbr = "==3.1.1"
psutil = "==5.4.3"
Expand All @@ -43,7 +43,6 @@ requests = "==2.20.0"
snowballstemmer = "==1.2.1"
thrift = "==0.11.0"
thrift-connector = "==0.23"
typed-ast = "==1.1.0"
"urllib3" = "==1.22"
werkzeug = "==0.14.1"
wtforms = "==2.1"
Expand Down
62 changes: 32 additions & 30 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion search/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import werkzeug


def get_application_config(app: Flask = None) -> Union[dict, os._Environ]:
def get_application_config(app: Optional[Union[Flask, object]] = None) -> Union[dict, os._Environ]:
"""
Get a configuration from the current app, or fall back to env.

Expand Down
4 changes: 2 additions & 2 deletions search/controllers/advanced/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def search(request_params: MultiDict) -> Response:
has_classic = False
for key in request_params.keys():
if key.startswith('terms-') and key.endswith('-term'):
value = request_params.get(key)
i = re.search('terms-([0-9])+-term', key).group(1)
value: str = request_params.get(key) # type: ignore
i = re.search('terms-([0-9])+-term', key).group(1) # type: ignore
field = request_params.get(f'terms-{i}-field')
# We are only looking for this syntax in the author search, or
# in an all-fields search.
Expand Down
9 changes: 3 additions & 6 deletions search/controllers/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ def _get_date_params(params: MultiDict, query_terms: List) \
dt = pytz.utc.localize(dt)
dt = dt.replace(tzinfo=EASTERN)
except ValueError:
raise BadRequest({'field': field, 'reason': 'invalid datetime'})
raise BadRequest(f'Invalid datetime in {field}')
date_params[field] = dt
query_terms.append({'parameter': field, 'value': dt})
if 'date_type' in params:
date_params['date_type'] = params.get('date_type')
date_params['date_type'] = params.get('date_type') # type: ignore
query_terms.append({'parameter': 'date_type',
'value': date_params['date_type']})
if date_params:
Expand Down Expand Up @@ -192,9 +192,6 @@ def _get_classification(value: str, field: str, query_terms: List) \
try:
clsns = _to_classification(value, query_terms)
except ValueError:
raise BadRequest({
'field': field,
'reason': 'not a valid classification term'
})
raise BadRequest(f'Not a valid classification term: {field}={value}')
query_terms.append({'parameter': field, 'value': value})
return clsns
5 changes: 3 additions & 2 deletions search/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def create_ui_web_app() -> Flask:
logging.getLogger('botocore').setLevel(logging.ERROR)

app = Flask('search')
app.config.from_pyfile('config.py')
app.config.from_pyfile('config.py') # type: ignore
app.url_map.converters['archive'] = ArchiveConverter

index.init_app(app)
Expand All @@ -47,7 +47,7 @@ def create_api_web_app() -> Flask:

app = Flask('search')
app.json_encoder = ISO8601JSONEncoder
app.config.from_pyfile('config.py')
app.config.from_pyfile('config.py') # type: ignore

index.init_app(app)

Expand All @@ -62,3 +62,4 @@ def create_api_web_app() -> Flask:
app.errorhandler(error)(handler)

return app