Skip to content

Add pre-commit tool to repository, and run on all files #730

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

Merged
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
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
- repo: git://github.com/pre-commit/pre-commit-hooks
sha: v0.8.0
hooks:
- id: autopep8-wrapper
args:
- -i
- --ignore=E128,E309,E501
exclude: ^docs/.*$
- id: check-json
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
exclude: ^docs/.*$
- id: trailing-whitespace
- id: pretty-format-json
args:
- --autofix
2 changes: 1 addition & 1 deletion UPGRADE-v2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ Now you can create abstact types super easily, without the need of subclassing t
class Base(ObjectType):
class Meta:
abstract = True

id = ID()

def resolve_id(self, info):
Expand Down
2 changes: 1 addition & 1 deletion examples/complex_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def resolve_address(self, info, geo):


class CreateAddress(graphene.Mutation):

class Arguments:
geo = GeoInput(required=True)

Expand Down
22 changes: 22 additions & 0 deletions graphene/pyutils/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,19 +662,25 @@ def __new__(cls, value):
if member.value == value:
return member
raise ValueError("%s is not a valid %s" % (value, cls.__name__))


temp_enum_dict['__new__'] = __new__
del __new__


def __repr__(self):
return "<%s.%s: %r>" % (
self.__class__.__name__, self._name_, self._value_)


temp_enum_dict['__repr__'] = __repr__
del __repr__


def __str__(self):
return "%s.%s" % (self.__class__.__name__, self._name_)


temp_enum_dict['__str__'] = __str__
del __str__

Expand Down Expand Up @@ -705,6 +711,8 @@ def __format__(self, format_spec):
cls = self._member_type_
val = self.value
return cls.__format__(val, format_spec)


temp_enum_dict['__format__'] = __format__
del __format__

Expand Down Expand Up @@ -751,6 +759,8 @@ def __eq__(self, other):
if isinstance(other, self.__class__):
return self is other
return NotImplemented


temp_enum_dict['__eq__'] = __eq__
del __eq__

Expand All @@ -759,18 +769,24 @@ def __ne__(self, other):
if isinstance(other, self.__class__):
return self is not other
return NotImplemented


temp_enum_dict['__ne__'] = __ne__
del __ne__


def __hash__(self):
return hash(self._name_)


temp_enum_dict['__hash__'] = __hash__
del __hash__


def __reduce_ex__(self, proto):
return self.__class__, (self._value_, )


temp_enum_dict['__reduce_ex__'] = __reduce_ex__
del __reduce_ex__

Expand All @@ -785,13 +801,17 @@ def __reduce_ex__(self, proto):
@_RouteClassAttributeToGetattr
def name(self):
return self._name_


temp_enum_dict['name'] = name
del name


@_RouteClassAttributeToGetattr
def value(self):
return self._value_


temp_enum_dict['value'] = value
del value

Expand All @@ -817,6 +837,8 @@ def _convert(cls, name, module, filter, source=None):
module_globals.update(cls.__members__)
module_globals[name] = cls
return cls


temp_enum_dict['_convert'] = _convert
del _convert

Expand Down
44 changes: 22 additions & 22 deletions graphene/pyutils/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def formatannotation(annotation, base_module=None):
if isinstance(annotation, type):
if annotation.__module__ in ('builtins', '__builtin__', base_module):
return annotation.__name__
return annotation.__module__+'.'+annotation.__name__
return annotation.__module__ + '.' + annotation.__name__
return repr(annotation)


Expand Down Expand Up @@ -126,7 +126,7 @@ def signature(obj):
_partial_kwarg=True)

elif (param.kind not in (_VAR_KEYWORD, _VAR_POSITIONAL) and
not param._partial_kwarg):
not param._partial_kwarg):
new_params.pop(arg_name)

return sig.replace(parameters=new_params.values())
Expand Down Expand Up @@ -193,11 +193,11 @@ def __repr__(self):
return '<_ParameterKind: {0!r}>'.format(self._name)


_POSITIONAL_ONLY = _ParameterKind(0, name='POSITIONAL_ONLY')
_POSITIONAL_OR_KEYWORD = _ParameterKind(1, name='POSITIONAL_OR_KEYWORD')
_VAR_POSITIONAL = _ParameterKind(2, name='VAR_POSITIONAL')
_KEYWORD_ONLY = _ParameterKind(3, name='KEYWORD_ONLY')
_VAR_KEYWORD = _ParameterKind(4, name='VAR_KEYWORD')
_POSITIONAL_ONLY = _ParameterKind(0, name='POSITIONAL_ONLY')
_POSITIONAL_OR_KEYWORD = _ParameterKind(1, name='POSITIONAL_OR_KEYWORD')
_VAR_POSITIONAL = _ParameterKind(2, name='VAR_POSITIONAL')
_KEYWORD_ONLY = _ParameterKind(3, name='KEYWORD_ONLY')
_VAR_KEYWORD = _ParameterKind(4, name='VAR_KEYWORD')


class Parameter(object):
Expand All @@ -220,11 +220,11 @@ class Parameter(object):

__slots__ = ('_name', '_kind', '_default', '_annotation', '_partial_kwarg')

POSITIONAL_ONLY = _POSITIONAL_ONLY
POSITIONAL_OR_KEYWORD = _POSITIONAL_OR_KEYWORD
VAR_POSITIONAL = _VAR_POSITIONAL
KEYWORD_ONLY = _KEYWORD_ONLY
VAR_KEYWORD = _VAR_KEYWORD
POSITIONAL_ONLY = _POSITIONAL_ONLY
POSITIONAL_OR_KEYWORD = _POSITIONAL_OR_KEYWORD
VAR_POSITIONAL = _VAR_POSITIONAL
KEYWORD_ONLY = _KEYWORD_ONLY
VAR_KEYWORD = _VAR_KEYWORD

empty = _empty

Expand Down Expand Up @@ -366,7 +366,7 @@ def args(self):
args = []
for param_name, param in self._signature.parameters.items():
if (param.kind in (_VAR_KEYWORD, _KEYWORD_ONLY) or
param._partial_kwarg):
param._partial_kwarg):
# Keyword arguments mapped by 'functools.partial'
# (Parameter._partial_kwarg is True) are mapped
# in 'BoundArguments.kwargs', along with VAR_KEYWORD &
Expand Down Expand Up @@ -396,7 +396,7 @@ def kwargs(self):
for param_name, param in self._signature.parameters.items():
if not kwargs_started:
if (param.kind in (_VAR_KEYWORD, _KEYWORD_ONLY) or
param._partial_kwarg):
param._partial_kwarg):
kwargs_started = True
else:
if param_name not in self.arguments:
Expand Down Expand Up @@ -494,7 +494,7 @@ def __init__(self, parameters=None, return_annotation=_empty,
params[name] = param
else:
params = OrderedDict(((param.name, param)
for param in parameters))
for param in parameters))

self._parameters = params
self._return_annotation = return_annotation
Expand Down Expand Up @@ -604,8 +604,8 @@ def __hash__(self):

def __eq__(self, other):
if (not issubclass(type(other), Signature) or
self.return_annotation != other.return_annotation or
len(self.parameters) != len(other.parameters)):
self.return_annotation != other.return_annotation or
len(self.parameters) != len(other.parameters)):
return False

other_positions = dict((param, idx)
Expand All @@ -627,7 +627,7 @@ def __eq__(self, other):
return False
else:
if (idx != other_idx or
param != other.parameters[param_name]):
param != other.parameters[param_name]):
return False

return True
Expand Down Expand Up @@ -680,7 +680,7 @@ def _bind(self, args, kwargs, partial=False):
parameters_ex = (param,)
break
elif (param.kind == _VAR_KEYWORD or
param.default is not _empty):
param.default is not _empty):
# That's fine too - we have a default value for this
# parameter. So, lets start parsing `kwargs`, starting
# with the current parameter
Expand Down Expand Up @@ -730,7 +730,7 @@ def _bind(self, args, kwargs, partial=False):
# Signature object (but let's have this check here
# to ensure correct behaviour just in case)
raise TypeError('{arg!r} parameter is positional only, '
'but was passed as a keyword'. \
'but was passed as a keyword'.
format(arg=param.name))

if param.kind == _VAR_KEYWORD:
Expand All @@ -747,8 +747,8 @@ def _bind(self, args, kwargs, partial=False):
# parameter, left alone by the processing of positional
# arguments.
if (not partial and param.kind != _VAR_POSITIONAL and
param.default is _empty):
raise TypeError('{arg!r} parameter lacking default value'. \
param.default is _empty):
raise TypeError('{arg!r} parameter lacking default value'.
format(arg=param_name))

else:
Expand Down
1 change: 1 addition & 0 deletions graphene/relay/tests/test_node_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Meta:
class RootQuery(ObjectType):
node = CustomNode.Field()


schema = Schema(query=RootQuery, types=[User, Photo])


Expand Down
2 changes: 1 addition & 1 deletion graphene/types/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init_subclass_with_meta__(cls, **options):
def test_basetype():
class MyBaseType(CustomType):
pass

assert isinstance(MyBaseType._meta, CustomOptions)
assert MyBaseType._meta.name == "MyBaseType"
assert MyBaseType._meta.description is None
Expand Down
10 changes: 7 additions & 3 deletions graphene/types/tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,27 @@ def test_time_query():
assert not result.errors
assert result.data == {'time': isoformat}


def test_bad_datetime_query():
not_a_date = "Some string that's not a date"

result = schema.execute('''{ datetime(in: "%s") }''' % not_a_date)

assert len(result.errors) == 1
assert isinstance(result.errors[0], GraphQLError)
assert result.data == None


def test_bad_date_query():
not_a_date = "Some string that's not a date"

result = schema.execute('''{ date(in: "%s") }''' % not_a_date)

assert len(result.errors) == 1
assert isinstance(result.errors[0], GraphQLError)
assert result.data == None


def test_bad_time_query():
not_a_date = "Some string that's not a date"

Expand All @@ -82,6 +85,7 @@ def test_bad_time_query():
assert isinstance(result.errors[0], GraphQLError)
assert result.data == None


def test_datetime_query_variable():
now = datetime.datetime.now().replace(tzinfo=pytz.utc)
isoformat = now.isoformat()
Expand Down
1 change: 1 addition & 0 deletions graphene/types/tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Query(ObjectType):
def resolve_json(self, info, input):
return input


schema = Schema(query=Query)


Expand Down
1 change: 1 addition & 0 deletions graphene/types/tests/test_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Query(ObjectType):
def resolve_uuid(self, info, input):
return input


schema = Schema(query=Query)


Expand Down
5 changes: 5 additions & 0 deletions graphene/utils/tests/test_annotate.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import pytest
from ..annotate import annotate


def func(a, b, *c, **d):
pass


annotations = {
'a': int,
'b': str,
'c': list,
'd': dict
}


def func_with_annotations(a, b, *c, **d):
pass


func_with_annotations.__annotations__ = annotations


Expand Down
Loading