Repository: 15five/scim2-filter-parser

Issue:
Return NamedTuple rather than tuple.
It would be nice to return a NamedTuple instead of a tuple here: 

https://github.com/15five/scim2-filter-parser/blob/7ddc216f8c3dd1cdb2152944187e8f7f5ee07be2/src/scim2_filter_parser/transpilers/sql.py#L148

This way parts of each path could be accessed by name rather than by index in the tuple.

Discussion:

Patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 12a5d4f..178f172 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,6 +1,10 @@
 CHANGE LOG
 ==========
 
+0.3.5
+-----
+- Update the sql.Transpiler to collect namedtuples rather than tuples for attr paths
+
 0.3.4
 -----
 - Update tox.ini and clean up linting errors
diff --git a/setup.py b/setup.py
index bbf57bf..bd16f70 100644
--- a/setup.py
+++ b/setup.py
@@ -14,7 +14,7 @@ def long_description():
 
 setup(
     name='scim2-filter-parser',
-    version='0.3.4',
+    version='0.3.5',
     description='A customizable parser/transpiler for SCIM2.0 filters',
     url='https://github.com/15five/scim2-filter-parser',
     maintainer='Paul Logston',
diff --git a/src/scim2_filter_parser/transpilers/sql.py b/src/scim2_filter_parser/transpilers/sql.py
index 6254f1e..2107758 100644
--- a/src/scim2_filter_parser/transpilers/sql.py
+++ b/src/scim2_filter_parser/transpilers/sql.py
@@ -4,9 +4,12 @@ clause based on a SCIM filter.
 """
 import ast
 import string
+import collections
 
 from .. import ast as scim2ast
 
+AttrPath = collections.namedtuple('AttrPath', ['attr_name', 'sub_attr', 'uri'])
+
 
 class Transpiler(ast.NodeTransformer):
     """
@@ -145,7 +148,7 @@ class Transpiler(ast.NodeTransformer):
 
         # Convert attr_name to another value based on map.
         # Otherwise, return None.
-        attr_path_tuple = (attr_name_value, sub_attr_value, uri_value)
+        attr_path_tuple = AttrPath(attr_name_value, sub_attr_value, uri_value)
         self.attr_paths.append(attr_path_tuple)
         return self.attr_map.get(attr_path_tuple)
 


Test patch:
diff --git a/tests/test_transpiler.py b/tests/test_transpiler.py
index b8e1bb4..280c2d3 100644
--- a/tests/test_transpiler.py
+++ b/tests/test_transpiler.py
@@ -36,6 +36,16 @@ class RFCExamples(TestCase):
         self.assertEqual(expected_sql, sql, query)
         self.assertEqual(expected_params, params, query)
 
+    def test_attr_paths_are_created(self):
+        query = 'userName eq "bjensen"'
+        tokens = self.lexer.tokenize(query)
+        ast = self.parser.parse(tokens)
+        self.transpiler.transpile(ast)
+
+        self.assertEqual(len(self.transpiler.attr_paths), 1)
+        for path in self.transpiler.attr_paths:
+            self.assertTrue(isinstance(path, transpile_sql.AttrPath))
+
     def test_username_eq(self):
         query = 'userName eq "bjensen"'
         sql = "username = {a}"