Skip to content

Arrays with ints is broken #44

@jdhedden

Description

@jdhedden
> echo -e '1\t2' | filter -c1 odd
Traceback (most recent call last):
  File "/home/jdhedden/bin/filter", line 6, in <module>
    Filter().run()
  File "/mnt/data/Computer/Linux/shell-functools/ft/ft/command.py", line 101, in run
    self.handle_input(value)
  File "/mnt/data/Computer/Linux/shell-functools/ft/ft/commands/filter.py", line 34, in handle_input
    self.print_formatted(value)
  File "/mnt/data/Computer/Linux/shell-functools/ft/ft/command.py", line 78, in print_formatted
    formatted = ftformat(result)
  File "/mnt/data/Computer/Linux/shell-functools/ft/ft/internal.py", line 17, in ftformat
    return "\t".join(map(ftformat, val.value))
TypeError: sequence item 0: expected str instance, int found

Offered fix:

diff --git a/ft/ft/internal.py b/ft/ft/internal.py
index 33ee227..b8a981f 100644
--- a/ft/ft/internal.py
+++ b/ft/ft/internal.py
@@ -13,7 +13,7 @@ def colored(inp, col):
 
 def ftformat(val):
     if val.fttype == T_ARRAY:
-        return "\t".join(map(ftformat, val.value))
+        return "\t".join(map(str, map(ftformat, val.value)))
     elif val.fttype == T_PATH:
         return colored(val.value, "cyan")
     elif val.fttype == T_STRING:

Result:

> echo -e '1\t2' | filter -c1 odd
1	2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions