mirror of
				https://github.com/graphql-python/graphene.git
				synced 2025-10-30 23:47:55 +03:00 
			
		
		
		
	Merge pull request #730 from dan98765/add_pre_commit_tool_to_repo
Add pre-commit tool to repository, and run on all files
This commit is contained in:
		
						commit
						4720f7743e
					
				
							
								
								
									
										17
									
								
								.pre-commit-config.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								.pre-commit-config.yaml
									
									
									
									
									
										Normal file
									
								
							|  | @ -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 | ||||||
|  | @ -662,6 +662,8 @@ def __new__(cls, value): | ||||||
|             if member.value == value: |             if member.value == value: | ||||||
|                 return member |                 return member | ||||||
|     raise ValueError("%s is not a valid %s" % (value, cls.__name__)) |     raise ValueError("%s is not a valid %s" % (value, cls.__name__)) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| temp_enum_dict['__new__'] = __new__ | temp_enum_dict['__new__'] = __new__ | ||||||
| del __new__ | del __new__ | ||||||
| 
 | 
 | ||||||
|  | @ -669,12 +671,16 @@ del __new__ | ||||||
| def __repr__(self): | def __repr__(self): | ||||||
|     return "<%s.%s: %r>" % ( |     return "<%s.%s: %r>" % ( | ||||||
|         self.__class__.__name__, self._name_, self._value_) |         self.__class__.__name__, self._name_, self._value_) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| temp_enum_dict['__repr__'] = __repr__ | temp_enum_dict['__repr__'] = __repr__ | ||||||
| del __repr__ | del __repr__ | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def __str__(self): | def __str__(self): | ||||||
|     return "%s.%s" % (self.__class__.__name__, self._name_) |     return "%s.%s" % (self.__class__.__name__, self._name_) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| temp_enum_dict['__str__'] = __str__ | temp_enum_dict['__str__'] = __str__ | ||||||
| del __str__ | del __str__ | ||||||
| 
 | 
 | ||||||
|  | @ -705,6 +711,8 @@ def __format__(self, format_spec): | ||||||
|         cls = self._member_type_ |         cls = self._member_type_ | ||||||
|         val = self.value |         val = self.value | ||||||
|     return cls.__format__(val, format_spec) |     return cls.__format__(val, format_spec) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| temp_enum_dict['__format__'] = __format__ | temp_enum_dict['__format__'] = __format__ | ||||||
| del __format__ | del __format__ | ||||||
| 
 | 
 | ||||||
|  | @ -751,6 +759,8 @@ def __eq__(self, other): | ||||||
|     if isinstance(other, self.__class__): |     if isinstance(other, self.__class__): | ||||||
|         return self is other |         return self is other | ||||||
|     return NotImplemented |     return NotImplemented | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| temp_enum_dict['__eq__'] = __eq__ | temp_enum_dict['__eq__'] = __eq__ | ||||||
| del __eq__ | del __eq__ | ||||||
| 
 | 
 | ||||||
|  | @ -759,18 +769,24 @@ def __ne__(self, other): | ||||||
|     if isinstance(other, self.__class__): |     if isinstance(other, self.__class__): | ||||||
|         return self is not other |         return self is not other | ||||||
|     return NotImplemented |     return NotImplemented | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| temp_enum_dict['__ne__'] = __ne__ | temp_enum_dict['__ne__'] = __ne__ | ||||||
| del __ne__ | del __ne__ | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def __hash__(self): | def __hash__(self): | ||||||
|     return hash(self._name_) |     return hash(self._name_) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| temp_enum_dict['__hash__'] = __hash__ | temp_enum_dict['__hash__'] = __hash__ | ||||||
| del __hash__ | del __hash__ | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def __reduce_ex__(self, proto): | def __reduce_ex__(self, proto): | ||||||
|     return self.__class__, (self._value_, ) |     return self.__class__, (self._value_, ) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| temp_enum_dict['__reduce_ex__'] = __reduce_ex__ | temp_enum_dict['__reduce_ex__'] = __reduce_ex__ | ||||||
| del __reduce_ex__ | del __reduce_ex__ | ||||||
| 
 | 
 | ||||||
|  | @ -785,6 +801,8 @@ del __reduce_ex__ | ||||||
| @_RouteClassAttributeToGetattr | @_RouteClassAttributeToGetattr | ||||||
| def name(self): | def name(self): | ||||||
|     return self._name_ |     return self._name_ | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| temp_enum_dict['name'] = name | temp_enum_dict['name'] = name | ||||||
| del name | del name | ||||||
| 
 | 
 | ||||||
|  | @ -792,6 +810,8 @@ del name | ||||||
| @_RouteClassAttributeToGetattr | @_RouteClassAttributeToGetattr | ||||||
| def value(self): | def value(self): | ||||||
|     return self._value_ |     return self._value_ | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| temp_enum_dict['value'] = value | temp_enum_dict['value'] = value | ||||||
| del value | del value | ||||||
| 
 | 
 | ||||||
|  | @ -817,6 +837,8 @@ def _convert(cls, name, module, filter, source=None): | ||||||
|     module_globals.update(cls.__members__) |     module_globals.update(cls.__members__) | ||||||
|     module_globals[name] = cls |     module_globals[name] = cls | ||||||
|     return cls |     return cls | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| temp_enum_dict['_convert'] = _convert | temp_enum_dict['_convert'] = _convert | ||||||
| del _convert | del _convert | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -28,7 +28,7 @@ def formatannotation(annotation, base_module=None): | ||||||
|     if isinstance(annotation, type): |     if isinstance(annotation, type): | ||||||
|         if annotation.__module__ in ('builtins', '__builtin__', base_module): |         if annotation.__module__ in ('builtins', '__builtin__', base_module): | ||||||
|             return annotation.__name__ |             return annotation.__name__ | ||||||
|         return annotation.__module__+'.'+annotation.__name__ |         return annotation.__module__ + '.' + annotation.__name__ | ||||||
|     return repr(annotation) |     return repr(annotation) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -126,7 +126,7 @@ def signature(obj): | ||||||
|                                                      _partial_kwarg=True) |                                                      _partial_kwarg=True) | ||||||
| 
 | 
 | ||||||
|             elif (param.kind not in (_VAR_KEYWORD, _VAR_POSITIONAL) and |             elif (param.kind not in (_VAR_KEYWORD, _VAR_POSITIONAL) and | ||||||
|                             not param._partial_kwarg): |                   not param._partial_kwarg): | ||||||
|                 new_params.pop(arg_name) |                 new_params.pop(arg_name) | ||||||
| 
 | 
 | ||||||
|         return sig.replace(parameters=new_params.values()) |         return sig.replace(parameters=new_params.values()) | ||||||
|  | @ -193,11 +193,11 @@ class _ParameterKind(int): | ||||||
|         return '<_ParameterKind: {0!r}>'.format(self._name) |         return '<_ParameterKind: {0!r}>'.format(self._name) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| _POSITIONAL_ONLY        = _ParameterKind(0, name='POSITIONAL_ONLY') | _POSITIONAL_ONLY = _ParameterKind(0, name='POSITIONAL_ONLY') | ||||||
| _POSITIONAL_OR_KEYWORD  = _ParameterKind(1, name='POSITIONAL_OR_KEYWORD') | _POSITIONAL_OR_KEYWORD = _ParameterKind(1, name='POSITIONAL_OR_KEYWORD') | ||||||
| _VAR_POSITIONAL         = _ParameterKind(2, name='VAR_POSITIONAL') | _VAR_POSITIONAL = _ParameterKind(2, name='VAR_POSITIONAL') | ||||||
| _KEYWORD_ONLY           = _ParameterKind(3, name='KEYWORD_ONLY') | _KEYWORD_ONLY = _ParameterKind(3, name='KEYWORD_ONLY') | ||||||
| _VAR_KEYWORD            = _ParameterKind(4, name='VAR_KEYWORD') | _VAR_KEYWORD = _ParameterKind(4, name='VAR_KEYWORD') | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Parameter(object): | class Parameter(object): | ||||||
|  | @ -220,11 +220,11 @@ class Parameter(object): | ||||||
| 
 | 
 | ||||||
|     __slots__ = ('_name', '_kind', '_default', '_annotation', '_partial_kwarg') |     __slots__ = ('_name', '_kind', '_default', '_annotation', '_partial_kwarg') | ||||||
| 
 | 
 | ||||||
|     POSITIONAL_ONLY         = _POSITIONAL_ONLY |     POSITIONAL_ONLY = _POSITIONAL_ONLY | ||||||
|     POSITIONAL_OR_KEYWORD   = _POSITIONAL_OR_KEYWORD |     POSITIONAL_OR_KEYWORD = _POSITIONAL_OR_KEYWORD | ||||||
|     VAR_POSITIONAL          = _VAR_POSITIONAL |     VAR_POSITIONAL = _VAR_POSITIONAL | ||||||
|     KEYWORD_ONLY            = _KEYWORD_ONLY |     KEYWORD_ONLY = _KEYWORD_ONLY | ||||||
|     VAR_KEYWORD             = _VAR_KEYWORD |     VAR_KEYWORD = _VAR_KEYWORD | ||||||
| 
 | 
 | ||||||
|     empty = _empty |     empty = _empty | ||||||
| 
 | 
 | ||||||
|  | @ -366,7 +366,7 @@ class BoundArguments(object): | ||||||
|         args = [] |         args = [] | ||||||
|         for param_name, param in self._signature.parameters.items(): |         for param_name, param in self._signature.parameters.items(): | ||||||
|             if (param.kind in (_VAR_KEYWORD, _KEYWORD_ONLY) or |             if (param.kind in (_VAR_KEYWORD, _KEYWORD_ONLY) or | ||||||
|                                                     param._partial_kwarg): |                     param._partial_kwarg): | ||||||
|                 # Keyword arguments mapped by 'functools.partial' |                 # Keyword arguments mapped by 'functools.partial' | ||||||
|                 # (Parameter._partial_kwarg is True) are mapped |                 # (Parameter._partial_kwarg is True) are mapped | ||||||
|                 # in 'BoundArguments.kwargs', along with VAR_KEYWORD & |                 # in 'BoundArguments.kwargs', along with VAR_KEYWORD & | ||||||
|  | @ -396,7 +396,7 @@ class BoundArguments(object): | ||||||
|         for param_name, param in self._signature.parameters.items(): |         for param_name, param in self._signature.parameters.items(): | ||||||
|             if not kwargs_started: |             if not kwargs_started: | ||||||
|                 if (param.kind in (_VAR_KEYWORD, _KEYWORD_ONLY) or |                 if (param.kind in (_VAR_KEYWORD, _KEYWORD_ONLY) or | ||||||
|                                                 param._partial_kwarg): |                         param._partial_kwarg): | ||||||
|                     kwargs_started = True |                     kwargs_started = True | ||||||
|                 else: |                 else: | ||||||
|                     if param_name not in self.arguments: |                     if param_name not in self.arguments: | ||||||
|  | @ -494,7 +494,7 @@ class Signature(object): | ||||||
|                     params[name] = param |                     params[name] = param | ||||||
|             else: |             else: | ||||||
|                 params = OrderedDict(((param.name, param) |                 params = OrderedDict(((param.name, param) | ||||||
|                                                 for param in parameters)) |                                       for param in parameters)) | ||||||
| 
 | 
 | ||||||
|         self._parameters = params |         self._parameters = params | ||||||
|         self._return_annotation = return_annotation |         self._return_annotation = return_annotation | ||||||
|  | @ -604,8 +604,8 @@ class Signature(object): | ||||||
| 
 | 
 | ||||||
|     def __eq__(self, other): |     def __eq__(self, other): | ||||||
|         if (not issubclass(type(other), Signature) or |         if (not issubclass(type(other), Signature) or | ||||||
|                     self.return_annotation != other.return_annotation or |             self.return_annotation != other.return_annotation or | ||||||
|                     len(self.parameters) != len(other.parameters)): |                 len(self.parameters) != len(other.parameters)): | ||||||
|             return False |             return False | ||||||
| 
 | 
 | ||||||
|         other_positions = dict((param, idx) |         other_positions = dict((param, idx) | ||||||
|  | @ -627,7 +627,7 @@ class Signature(object): | ||||||
|                     return False |                     return False | ||||||
|                 else: |                 else: | ||||||
|                     if (idx != other_idx or |                     if (idx != other_idx or | ||||||
|                                     param != other.parameters[param_name]): |                             param != other.parameters[param_name]): | ||||||
|                         return False |                         return False | ||||||
| 
 | 
 | ||||||
|         return True |         return True | ||||||
|  | @ -680,7 +680,7 @@ class Signature(object): | ||||||
|                         parameters_ex = (param,) |                         parameters_ex = (param,) | ||||||
|                         break |                         break | ||||||
|                     elif (param.kind == _VAR_KEYWORD or |                     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 |                         # That's fine too - we have a default value for this | ||||||
|                         # parameter.  So, lets start parsing `kwargs`, starting |                         # parameter.  So, lets start parsing `kwargs`, starting | ||||||
|                         # with the current parameter |                         # with the current parameter | ||||||
|  | @ -730,7 +730,7 @@ class Signature(object): | ||||||
|                 # Signature object (but let's have this check here |                 # Signature object (but let's have this check here | ||||||
|                 # to ensure correct behaviour just in case) |                 # to ensure correct behaviour just in case) | ||||||
|                 raise TypeError('{arg!r} parameter is positional only, ' |                 raise TypeError('{arg!r} parameter is positional only, ' | ||||||
|                                 'but was passed as a keyword'. \ |                                 'but was passed as a keyword'. | ||||||
|                                 format(arg=param.name)) |                                 format(arg=param.name)) | ||||||
| 
 | 
 | ||||||
|             if param.kind == _VAR_KEYWORD: |             if param.kind == _VAR_KEYWORD: | ||||||
|  | @ -747,8 +747,8 @@ class Signature(object): | ||||||
|                 # parameter, left alone by the processing of positional |                 # parameter, left alone by the processing of positional | ||||||
|                 # arguments. |                 # arguments. | ||||||
|                 if (not partial and param.kind != _VAR_POSITIONAL and |                 if (not partial and param.kind != _VAR_POSITIONAL and | ||||||
|                                                     param.default is _empty): |                         param.default is _empty): | ||||||
|                     raise TypeError('{arg!r} parameter lacking default value'. \ |                     raise TypeError('{arg!r} parameter lacking default value'. | ||||||
|                                     format(arg=param_name)) |                                     format(arg=param_name)) | ||||||
| 
 | 
 | ||||||
|             else: |             else: | ||||||
|  |  | ||||||
|  | @ -54,6 +54,7 @@ photo_data = { | ||||||
| class RootQuery(ObjectType): | class RootQuery(ObjectType): | ||||||
|     node = CustomNode.Field() |     node = CustomNode.Field() | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| schema = Schema(query=RootQuery, types=[User, Photo]) | schema = Schema(query=RootQuery, types=[User, Photo]) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -55,6 +55,7 @@ def test_time_query(): | ||||||
|     assert not result.errors |     assert not result.errors | ||||||
|     assert result.data == {'time': isoformat} |     assert result.data == {'time': isoformat} | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def test_bad_datetime_query(): | def test_bad_datetime_query(): | ||||||
|     not_a_date = "Some string that's not a date" |     not_a_date = "Some string that's not a date" | ||||||
| 
 | 
 | ||||||
|  | @ -64,6 +65,7 @@ def test_bad_datetime_query(): | ||||||
|     assert isinstance(result.errors[0], GraphQLError) |     assert isinstance(result.errors[0], GraphQLError) | ||||||
|     assert result.data == None |     assert result.data == None | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def test_bad_date_query(): | def test_bad_date_query(): | ||||||
|     not_a_date = "Some string that's not a date" |     not_a_date = "Some string that's not a date" | ||||||
| 
 | 
 | ||||||
|  | @ -73,6 +75,7 @@ def test_bad_date_query(): | ||||||
|     assert isinstance(result.errors[0], GraphQLError) |     assert isinstance(result.errors[0], GraphQLError) | ||||||
|     assert result.data == None |     assert result.data == None | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def test_bad_time_query(): | def test_bad_time_query(): | ||||||
|     not_a_date = "Some string that's not a date" |     not_a_date = "Some string that's not a date" | ||||||
| 
 | 
 | ||||||
|  | @ -82,6 +85,7 @@ def test_bad_time_query(): | ||||||
|     assert isinstance(result.errors[0], GraphQLError) |     assert isinstance(result.errors[0], GraphQLError) | ||||||
|     assert result.data == None |     assert result.data == None | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def test_datetime_query_variable(): | def test_datetime_query_variable(): | ||||||
|     now = datetime.datetime.now().replace(tzinfo=pytz.utc) |     now = datetime.datetime.now().replace(tzinfo=pytz.utc) | ||||||
|     isoformat = now.isoformat() |     isoformat = now.isoformat() | ||||||
|  |  | ||||||
|  | @ -10,6 +10,7 @@ class Query(ObjectType): | ||||||
|     def resolve_json(self, info, input): |     def resolve_json(self, info, input): | ||||||
|         return input |         return input | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| schema = Schema(query=Query) | schema = Schema(query=Query) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -9,6 +9,7 @@ class Query(ObjectType): | ||||||
|     def resolve_uuid(self, info, input): |     def resolve_uuid(self, info, input): | ||||||
|         return input |         return input | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| schema = Schema(query=Query) | schema = Schema(query=Query) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,9 +1,11 @@ | ||||||
| import pytest | import pytest | ||||||
| from ..annotate import annotate | from ..annotate import annotate | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def func(a, b, *c, **d): | def func(a, b, *c, **d): | ||||||
|     pass |     pass | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| annotations = { | annotations = { | ||||||
|     'a': int, |     'a': int, | ||||||
|     'b': str, |     'b': str, | ||||||
|  | @ -11,8 +13,11 @@ annotations = { | ||||||
|     'd': dict |     'd': dict | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def func_with_annotations(a, b, *c, **d): | def func_with_annotations(a, b, *c, **d): | ||||||
|     pass |     pass | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| func_with_annotations.__annotations__ = annotations | func_with_annotations.__annotations__ = annotations | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -4,6 +4,7 @@ from .. import deprecated | ||||||
| 
 | 
 | ||||||
| def test_resolve_only_args(mocker): | def test_resolve_only_args(mocker): | ||||||
|     mocker.patch.object(deprecated, 'warn_deprecation') |     mocker.patch.object(deprecated, 'warn_deprecation') | ||||||
|  | 
 | ||||||
|     def resolver(root, **args): |     def resolver(root, **args): | ||||||
|         return root, args |         return root, args | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										11
									
								
								tox.ini
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								tox.ini
									
									
									
									
									
								
							|  | @ -1,5 +1,5 @@ | ||||||
| [tox] | [tox] | ||||||
| envlist = flake8,py27,py33,py34,py35,py36,pypy | envlist = flake8,py27,py33,py34,py35,py36,pre-commit,pypy | ||||||
| skipsdist = true | skipsdist = true | ||||||
| 
 | 
 | ||||||
| [testenv] | [testenv] | ||||||
|  | @ -20,6 +20,15 @@ setenv = | ||||||
| commands= | commands= | ||||||
|     py.test |     py.test | ||||||
| 
 | 
 | ||||||
|  | [testenv:pre-commit] | ||||||
|  | basepython=python3.6 | ||||||
|  | deps = | ||||||
|  |     pre-commit>0.12.0 | ||||||
|  | setenv = | ||||||
|  |     LC_CTYPE=en_US.UTF-8 | ||||||
|  | commands = | ||||||
|  |     pre-commit {posargs:run --all-files} | ||||||
|  | 
 | ||||||
| [testenv:flake8] | [testenv:flake8] | ||||||
| deps = flake8 | deps = flake8 | ||||||
| commands = | commands = | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user