1 | # ~*~ coding: utf-8 ~*~ |
||
0 ignored issues
–
show
|
|||
2 | #- |
||
3 | # OSMAlchemy - OpenStreetMap to SQLAlchemy bridge |
||
4 | # Copyright (c) 2016 Michael Bayer <[email protected]> |
||
5 | # Copyright (c) 2016 Dominik George <[email protected]> |
||
6 | # |
||
7 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
||
8 | # of this software and associated documentation files (the "Software"), to deal |
||
9 | # in the Software without restriction, including without limitation the rights |
||
10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
11 | # copies of the Software, and to permit persons to whom the Software is |
||
12 | # furnished to do so, subject to the following conditions: |
||
13 | # |
||
14 | # The above copyright notice and this permission notice shall be included in all |
||
15 | # copies or substantial portions of the Software. |
||
16 | # |
||
17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||
23 | # SOFTWARE. |
||
24 | |||
25 | 1 | def monkey_patch_sqlalchemy(): |
|
0 ignored issues
–
show
This function should have a docstring.
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods: class SomeClass:
def some_method(self):
"""Do x and return foo."""
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions. ![]() |
|||
26 | 1 | from sqlalchemy.ext.associationproxy import AssociationProxy |
|
27 | 1 | from sqlalchemy.util import memoized_property |
|
28 | |||
29 | # Monkey patch support for chained association proxy queries into SQLAlchemy |
||
30 | # https://bitbucket.org/zzzeek/sqlalchemy/issues/3769/chained-any-has-with-association-proxy |
||
31 | 1 | if not hasattr(AssociationProxy, "_unwrap_target_assoc_proxy"): |
|
32 | 1 | def _unwrap_target_assoc_proxy(self): |
|
33 | attr = getattr(self.target_class, self.value_attr) |
||
34 | if isinstance(attr, AssociationProxy): |
||
35 | return attr, getattr(self.target_class, attr.target_collection) |
||
36 | return None, None |
||
37 | 1 | AssociationProxy._unwrap_target_assoc_proxy = memoized_property(_unwrap_target_assoc_proxy) |
|
0 ignored issues
–
show
It seems like
_unwrap_target_assoc_proxy was declared protected and should not be accessed from this context.
Prefixing a member variable class MyParent:
def __init__(self):
self._x = 1;
self.y = 2;
class MyChild(MyParent):
def some_method(self):
return self._x # Ok, since accessed from a child class
class AnotherClass:
def some_method(self, instance_of_my_child):
return instance_of_my_child._x # Would be flagged as AnotherClass is not
# a child class of MyParent
![]() |
|||
38 | |||
39 | 1 | orig_any = AssociationProxy.any |
|
40 | 1 | def any_(self, criterion=None, **kwargs): |
|
0 ignored issues
–
show
This function should have a docstring.
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods: class SomeClass:
def some_method(self):
"""Do x and return foo."""
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions. ![]() |
|||
41 | target_assoc, inner = self._unwrap_target_assoc_proxy |
||
0 ignored issues
–
show
It seems like
_unwrap_target_assoc_proxy was declared protected and should not be accessed from this context.
Prefixing a member variable class MyParent:
def __init__(self):
self._x = 1;
self.y = 2;
class MyChild(MyParent):
def some_method(self):
return self._x # Ok, since accessed from a child class
class AnotherClass:
def some_method(self, instance_of_my_child):
return instance_of_my_child._x # Would be flagged as AnotherClass is not
# a child class of MyParent
![]() |
|||
42 | if target_assoc is not None: |
||
43 | if target_assoc._target_is_object and target_assoc._uselist: |
||
0 ignored issues
–
show
It seems like
_target_is_object was declared protected and should not be accessed from this context.
Prefixing a member variable class MyParent:
def __init__(self):
self._x = 1;
self.y = 2;
class MyChild(MyParent):
def some_method(self):
return self._x # Ok, since accessed from a child class
class AnotherClass:
def some_method(self, instance_of_my_child):
return instance_of_my_child._x # Would be flagged as AnotherClass is not
# a child class of MyParent
![]() It seems like
_uselist was declared protected and should not be accessed from this context.
Prefixing a member variable class MyParent:
def __init__(self):
self._x = 1;
self.y = 2;
class MyChild(MyParent):
def some_method(self):
return self._x # Ok, since accessed from a child class
class AnotherClass:
def some_method(self, instance_of_my_child):
return instance_of_my_child._x # Would be flagged as AnotherClass is not
# a child class of MyParent
![]() |
|||
44 | inner = inner.any(criterion=criterion, **kwargs) |
||
45 | else: |
||
46 | inner = inner.has(criterion=criterion, **kwargs) |
||
47 | return self._comparator.any(inner) |
||
0 ignored issues
–
show
It seems like
_comparator was declared protected and should not be accessed from this context.
Prefixing a member variable class MyParent:
def __init__(self):
self._x = 1;
self.y = 2;
class MyChild(MyParent):
def some_method(self):
return self._x # Ok, since accessed from a child class
class AnotherClass:
def some_method(self, instance_of_my_child):
return instance_of_my_child._x # Would be flagged as AnotherClass is not
# a child class of MyParent
![]() |
|||
48 | orig_any(self, criterion, **kwargs) |
||
49 | 1 | AssociationProxy.any = any_ |
|
50 | |||
51 | 1 | orig_has = AssociationProxy.has |
|
52 | 1 | def has(self, criterion=None, **kwargs): |
|
0 ignored issues
–
show
This function should have a docstring.
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods: class SomeClass:
def some_method(self):
"""Do x and return foo."""
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions. ![]() |
|||
53 | target_assoc, inner = self._unwrap_target_assoc_proxy |
||
0 ignored issues
–
show
It seems like
_unwrap_target_assoc_proxy was declared protected and should not be accessed from this context.
Prefixing a member variable class MyParent:
def __init__(self):
self._x = 1;
self.y = 2;
class MyChild(MyParent):
def some_method(self):
return self._x # Ok, since accessed from a child class
class AnotherClass:
def some_method(self, instance_of_my_child):
return instance_of_my_child._x # Would be flagged as AnotherClass is not
# a child class of MyParent
![]() |
|||
54 | if target_assoc is not None: |
||
55 | if target_assoc._target_is_object and target_assoc._uselist: |
||
0 ignored issues
–
show
It seems like
_target_is_object was declared protected and should not be accessed from this context.
Prefixing a member variable class MyParent:
def __init__(self):
self._x = 1;
self.y = 2;
class MyChild(MyParent):
def some_method(self):
return self._x # Ok, since accessed from a child class
class AnotherClass:
def some_method(self, instance_of_my_child):
return instance_of_my_child._x # Would be flagged as AnotherClass is not
# a child class of MyParent
![]() It seems like
_uselist was declared protected and should not be accessed from this context.
Prefixing a member variable class MyParent:
def __init__(self):
self._x = 1;
self.y = 2;
class MyChild(MyParent):
def some_method(self):
return self._x # Ok, since accessed from a child class
class AnotherClass:
def some_method(self, instance_of_my_child):
return instance_of_my_child._x # Would be flagged as AnotherClass is not
# a child class of MyParent
![]() |
|||
56 | inner = inner.any(criterion=criterion, **kwargs) |
||
57 | else: |
||
58 | inner = inner.has(criterion=criterion, **kwargs) |
||
59 | return self._comparator.has(inner) |
||
0 ignored issues
–
show
It seems like
_comparator was declared protected and should not be accessed from this context.
Prefixing a member variable class MyParent:
def __init__(self):
self._x = 1;
self.y = 2;
class MyChild(MyParent):
def some_method(self):
return self._x # Ok, since accessed from a child class
class AnotherClass:
def some_method(self, instance_of_my_child):
return instance_of_my_child._x # Would be flagged as AnotherClass is not
# a child class of MyParent
![]() |
|||
60 | orig_has(self, criterion, **kwargs) |
||
61 | 1 | AssociationProxy.has = has |
|
62 | |||
63 | def monkey_patch_flask_restless(): |
||
0 ignored issues
–
show
This function should have a docstring.
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods: class SomeClass:
def some_method(self):
"""Do x and return foo."""
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions. ![]() |
|||
64 | try: |
||
65 | import flask_restless.helpers |
||
0 ignored issues
–
show
|
|||
66 | except: |
||
0 ignored issues
–
show
General except handlers without types should be used sparingly.
Typically, you would use general except handlers when you intend to specifically handle all types of errors, f.e. when logging. Otherwise, such general error handlers can mask errors in your application that you want to know of. ![]() |
|||
67 | return |
||
68 | |||
69 | # Monkey patch support for chained association proxy into Flask-Restless |
||
70 | # https://github.com/jfinkels/flask-restless/issues/578 |
||
71 | if hasattr(flask_restless.helpers, "get_related_association_proxy_model"): |
||
72 | from sqlalchemy.ext.associationproxy import AssociationProxy |
||
73 | |||
74 | def _get_related_association_proxy_model(attr): |
||
0 ignored issues
–
show
The name
_get_related_association_proxy_model does not conform to the function naming conventions ([a-z_][a-z0-9_]{2,30}$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() |
|||
75 | if isinstance(attr.remote_attr, AssociationProxy): |
||
76 | return _get_related_association_proxy_model(attr.remote_attr) |
||
77 | else: |
||
78 | prop = attr.remote_attr.property |
||
79 | for attribute in ('mapper', 'parent'): |
||
80 | if hasattr(prop, attribute): |
||
81 | return getattr(prop, attribute).class_ |
||
82 | return None |
||
83 | |||
84 | flask_restless.helpers.get_related_association_proxy_model = _get_related_association_proxy_model |
||
0 ignored issues
–
show
|
|||
85 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.