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

Remove inappropriate lint messages #90

Merged
merged 3 commits into from
Nov 22, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
69 changes: 30 additions & 39 deletions optimade/filtertransformers/mongo.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
from lark import Transformer, v_args, Token


class OperatorError(Exception):
pass


class UnknownMongoDBQueryError(Exception):
pass


op_expr = {"<": "$lt", "<=": "$lte", ">": "$gt", ">=": "$gte", "!=": "$ne", "=": "$eq"}


Expand Down Expand Up @@ -53,8 +45,7 @@ def atom(self, args):
if len(args) == 2:
field, predicate = next(((k, v) for k, v in args[1].items()))
return {field: {"$not": predicate}}
else:
return args[0]
return args[0]

def comparison(self, args):
field = args[0].value
Expand Down Expand Up @@ -111,9 +102,7 @@ def __init__(self):

def filter(self, arg):
# filter: expression*
if not arg:
return None
return arg[0]
return arg[0] if arg else None

@v_args(inline=True)
def constant(self, value):
Expand Down Expand Up @@ -154,10 +143,10 @@ def expression_phrase(self, arg):
if len(arg) == 1:
# without NOT
return arg[0]
else:
# with NOT
# TODO: This implementation probably fails in the case of `predicate_comparison` or `"(" expression ")"`
return {prop: {"$not": expr} for prop, expr in arg[1].items()}

# with NOT
# TODO: This implementation probably fails in the case of `predicate_comparison` or `"(" expression ")"`
return {prop: {"$not": expr} for prop, expr in arg[1].items()}

@v_args(inline=True)
def comparison(self, value):
Expand Down Expand Up @@ -185,10 +174,7 @@ def value_op_rhs(self, operator, value):

def known_op_rhs(self, arg):
# known_op_rhs: IS ( KNOWN | UNKNOWN )
if arg[1] == "KNOWN":
return {"$exists": True}
elif arg[1] == "UNKNOWN":
return {"$exists": False}
return {"$exists": arg[1] == "KNOWN"}

def fuzzy_string_op_rhs(self, arg):
# fuzzy_string_op_rhs: CONTAINS string | STARTS [ WITH ] string | ENDS [ WITH ] string
Expand All @@ -199,29 +185,31 @@ def fuzzy_string_op_rhs(self, arg):
else:
pattern = arg[1]

# CONTAINS
if arg[0] == "CONTAINS":
CasperWA marked this conversation as resolved.
Show resolved Hide resolved
return {"$regex": f"{pattern}"}
regex = f"{pattern}"
elif arg[0] == "STARTS":
return {"$regex": f"^{pattern}"}
regex = f"^{pattern}"
elif arg[0] == "ENDS":
return {"$regex": f"{pattern}$"}
regex = f"{pattern}$"
return {"$regex": regex}

def set_op_rhs(self, arg):
# set_op_rhs: HAS ( [ OPERATOR ] value | ALL value_list | ANY value_list | ONLY value_list )

if len(arg) == 2:
# only value without OPERATOR
return {"$in": arg[1:]}
else:
if arg[1] == "ALL":
raise NotImplementedError
elif arg[1] == "ANY":
raise NotImplementedError
elif arg[1] == "ONLY":
raise NotImplementedError
else:
# value with OPERATOR
raise NotImplementedError

if arg[1] == "ALL":
raise NotImplementedError
if arg[1] == "ANY":
fekad marked this conversation as resolved.
Show resolved Hide resolved
raise NotImplementedError
if arg[1] == "ONLY":
raise NotImplementedError

# value with OPERATOR
raise NotImplementedError

def set_zip_op_rhs(self, arg):
# set_zip_op_rhs: property_zip_addon HAS ( value_zip | ONLY value_zip_list | ALL value_zip_list |
Expand All @@ -233,8 +221,8 @@ def predicate_comparison(self, arg):
# TODO: https://stackoverflow.com/questions/7811163/query-for-documents-where-array-size-is-greater-than-1
if arg[2] == "=":
return {arg[1]: {"$size": arg[3]}}
else:
raise NotImplementedError

raise NotImplementedError

def property_zip_addon(self, arg):
# property_zip_addon: ":" property (":" property)*
Expand All @@ -253,9 +241,12 @@ def number(self, arg):
# number: SIGNED_INT | SIGNED_FLOAT
token = arg[0]
if token.type == "SIGNED_INT":
return int(token)
type_ = int
elif token.type == "SIGNED_FLOAT":
return float(token)
type_ = float
return type_(token)

def __default__(self, data, children, meta):
raise NotImplementedError
raise NotImplementedError(
f"Calling __default__, i.e., unknown grammar concept. data: {data}, children: {children}, meta: {meta}"
)
3 changes: 2 additions & 1 deletion optimade/models/entries.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# pylint: disable=line-too-long
from datetime import datetime
from typing import Optional, Dict, List
from pydantic import BaseModel, Schema, validator
from pydantic import BaseModel, Schema

from .jsonapi import Relationships, Attributes, Resource

Expand Down
1 change: 1 addition & 0 deletions optimade/models/jsonapi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module should reproduce JSON API v1.0 https://jsonapi.org/format/1.0/"""
# pylint: disable=no-name-in-module,no-self-argument
from typing import Optional, Set, Union, Any
from pydantic import BaseModel, UrlStr, Schema, validator

Expand Down
3 changes: 2 additions & 1 deletion optimade/models/structures.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=no-self-argument,line-too-long
from sys import float_info
from typing import List, Optional

Expand Down Expand Up @@ -123,7 +124,7 @@ def validate_sites_in_groups(cls, v):
sites = []
for group in v:
sites.extend(group)
if not (len(set(sites)) == len(sites)):
if len(set(sites)) != len(sites):
raise ValueError(
f"A site MUST NOT appear in more than one group. Given value: {v}"
)
Expand Down
6 changes: 2 additions & 4 deletions optimade/validator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
""" This module contains the ImplementationValidator class and corresponding
command line tools.

"""
""" This module contains the ImplementationValidator class and corresponding command line tools. """
# pylint: disable=line-too-long

from .validator import ImplementationValidator

Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pycodestyle]
ignore = E501