Repository: OpenMined/PySyft

Issue:
Reduce complexity of route_method_exception
Split the code from ```route_method_exception``` into two separate functions and remove the ```noqa: C901```.

**Describe alternatives you've considered**
Simplify the function such that no split is required.

**Additional context**
Code quality:
```
2020-04-29T13:13:32.5920184Z ./syft/exceptions.py:359:1: C901 'route_method_exception' is too complex (14)
2020-04-29T13:13:32.5920476Z def route_method_exception(exception, self, args_, kwargs_):
2020-04-29T13:13:32.5920733Z ^
```


Discussion:
hey , can i work on this issue?

Is the issue still open?I would like to work on it? @gmuraru 
Hey. If the issue is still present, you can grab it :D
Can you guide through how to produce the bug?
This issue has been marked stale because it has been open 30 days with no activity. Leave a comment or remove the `stale` label to unmark it. Otherwise, this will be closed in 7 days.
@gmuraru sir, I tried to solve the mentioned problem
```
2020-04-29T13:13:32.5920184Z ./syft/exceptions.py:359:1: C901 'route_method_exception' is too complex (14)
2020-04-29T13:13:32.5920476Z def route_method_exception(exception, self, args_, kwargs_):
2020-04-29T13:13:32.5920733Z ^
```
But, instead of converting ```route_method_exception``` to two separate methods I just reduced the ```if...elif``` statements.
And it seems to work properly, it shows positive results in both Flake8 test(after removing C901) and pytest.

Will this change work instead of separating the method?

Resolving patch:
diff --git a/syft/exceptions.py b/syft/exceptions.py
--- a/syft/exceptions.py
+++ b/syft/exceptions.py
@@ -360,25 +360,21 @@ class TranslationUnavailableError(Exception):
     pass
 
 
-def route_method_exception(exception, self, args_, kwargs_):  # noqa: C901
+def route_method_exception(exception, self, args_, kwargs_):
     try:
-        if self.is_wrapper:
-            if isinstance(self.child, sy.PointerTensor):
-                if len(args_) > 0:
-                    if not args_[0].is_wrapper:
-                        return TensorsNotCollocatedException(self, args_[0])
-                    elif isinstance(args_[0].child, sy.PointerTensor):
-                        if self.location != args_[0].child.location:
-                            return TensorsNotCollocatedException(self, args_[0])
+        if self.is_wrapper and isinstance(self.child, sy.PointerTensor) and len(args_) > 0:
+            if not args_[0].is_wrapper:
+                return TensorsNotCollocatedException(self, args_[0])
+            elif isinstance(args_[0].child, sy.PointerTensor):
+                if self.location != args_[0].child.location:
+                    return TensorsNotCollocatedException(self, args_[0])
 
         # if self is a normal tensor
-        elif isinstance(self, FrameworkTensor):
-            if len(args_) > 0:
-                if args_[0].is_wrapper:
-                    if isinstance(args_[0].child, sy.PointerTensor):
-                        return TensorsNotCollocatedException(self, args_[0])
-                elif isinstance(args_[0], sy.PointerTensor):
-                    return TensorsNotCollocatedException(self, args_[0])
+        elif isinstance(self, FrameworkTensor) and len(args_) > 0:
+            if args_[0].is_wrapper and isinstance(args_[0].child, sy.PointerTensor):
+                return TensorsNotCollocatedException(self, args_[0])
+            elif isinstance(args_[0], sy.PointerTensor):
+                return TensorsNotCollocatedException(self, args_[0])
     except:  # noqa: E722
         ""
     return exception


Test patch: