Repository: saulpw/visidata

Issue:
TSV file with column name "length" causes TypeError
**Small description**
Files in TSV format containing a column named `length` cannot be loaded.

**Expected result**
See content of TSV file.

**Actual result with screenshot**
An empty file is shown. In the footer line it says:
```
TypeError: 'property' object is not callable
```

**Steps to reproduce with sample data and a .vd**
Create a file named `test.tsv` with this content:
```
length
1
```
Then, try to open it:
```
vd test.tsv
```

**Additional context**
version 1.5.2



Discussion:
Hi @suhrig, thanks for the bug report.  This is a really good one, and I'm surprised we hadn't found it before! I'll look into it sometime soon, and hopefully get it fixed for the next 2.x release candidate.

Resolving patch:
diff --git a/visidata/utils.py b/visidata/utils.py
--- a/visidata/utils.py
+++ b/visidata/utils.py
@@ -70,17 +70,13 @@ class NamedListTemplate(list):
 
         def __init__(self, L=None, **kwargs):
             if L is None:
-                L = [None]*self.length()
-            elif len(L) < self.length():
-                L.extend([None]*(self.length() - len(L)))
+                L = [None]*len(self._fields)
+            elif len(L) < len(self._fields):
+                L.extend([None]*(len(self._fields) - len(L)))
             super().__init__(L)
             for k, v in kwargs.items():
                 setattr(self, k, v)
 
-        @classmethod
-        def length(cls):
-            return len(cls._fields)
-
         def __getattr__(self, k):
             'to enable .fieldname'
             try:
@@ -95,8 +91,4 @@ def __setattr__(self, k, v):
             except ValueError:
                 super().__setattr__(k, v)
 
-    for i, attrname in enumerate(fieldnames):
-        # create property getter/setter for each field
-        setattr(NamedListTemplate, attrname, property(operator.itemgetter(i), itemsetter(i)))
-
     return NamedListTemplate


Test patch:
diff --git a/tests/column-name-__name__.csv b/tests/column-name-__name__.csv
new file mode 100644
--- /dev/null
+++ b/tests/column-name-__name__.csv
@@ -0,0 +1,4 @@
+__name__,foo,bar,baz
+a,1,2,3
+b,4,5,6
+c,7,8,9
diff --git a/tests/column-name-__name__.vd b/tests/column-name-__name__.vd
new file mode 100644
--- /dev/null
+++ b/tests/column-name-__name__.vd
@@ -0,0 +1,2 @@
+sheet	col	row	longname	input	keystrokes	comment
+			open-file	tests/column-name-__name__.csv	o	
diff --git a/tests/column-name-_fields.csv b/tests/column-name-_fields.csv
new file mode 100644
--- /dev/null
+++ b/tests/column-name-_fields.csv
@@ -0,0 +1,4 @@
+_fields,foo,bar,baz
+a,1,2,3
+b,4,5,6
+c,7,8,9
diff --git a/tests/column-name-_fields.vd b/tests/column-name-_fields.vd
new file mode 100644
--- /dev/null
+++ b/tests/column-name-_fields.vd
@@ -0,0 +1,2 @@
+sheet	col	row	longname	input	keystrokes	comment
+			open-file	tests/column-name-_fields.csv	o	
diff --git a/tests/column-name-length.csv b/tests/column-name-length.csv
new file mode 100644
--- /dev/null
+++ b/tests/column-name-length.csv
@@ -0,0 +1,4 @@
+length,foo,bar,baz
+a,1,2,3
+b,4,5,6
+c,7,8,9
diff --git a/tests/column-name-length.vd b/tests/column-name-length.vd
new file mode 100644
--- /dev/null
+++ b/tests/column-name-length.vd
@@ -0,0 +1,2 @@
+sheet	col	row	longname	input	keystrokes	comment
+			open-file	tests/column-name-length.csv	o	
diff --git a/tests/golden/column-name-__name__.csv b/tests/golden/column-name-__name__.csv
new file mode 100644
--- /dev/null
+++ b/tests/golden/column-name-__name__.csv
@@ -0,0 +1,4 @@
+__name__,foo,bar,baz
+a,1,2,3
+b,4,5,6
+c,7,8,9
diff --git a/tests/golden/column-name-_fields.csv b/tests/golden/column-name-_fields.csv
new file mode 100644
--- /dev/null
+++ b/tests/golden/column-name-_fields.csv
@@ -0,0 +1,4 @@
+_fields,foo,bar,baz
+a,1,2,3
+b,4,5,6
+c,7,8,9
diff --git a/tests/golden/column-name-length.csv b/tests/golden/column-name-length.csv
new file mode 100644
--- /dev/null
+++ b/tests/golden/column-name-length.csv
@@ -0,0 +1,4 @@
+length,foo,bar,baz
+a,1,2,3
+b,4,5,6
+c,7,8,9