beets icon indicating copy to clipboard operation
beets copied to clipboard

Unicode object is not callable

Open willgrnr opened this issue 11 years ago • 7 comments

Upon using beet duplicates...

C:\Users\100557855>beet duplicates
Traceback (most recent call last):
  File "C:\Python27\Scripts\beet-script.py", line 9, in <module>
    load_entry_point('beets==1.3.11', 'console_scripts', 'beet')()
  File "c:\users\100557855\src\beets\beets\ui\__init__.py", line 953, in main
    _raw_main(args)
  File "c:\users\100557855\src\beets\beets\ui\__init__.py", line 943, in _raw_ma
in
    subcommand.func(lib, suboptions, subargs)
  File "c:\users\100557855\src\beets\beetsplug\duplicates.py", line 232, in _dup

    format=fmt.format(obj_count))
  File "c:\users\100557855\src\beets\beetsplug\duplicates.py", line 48, in _proc
ess_item
    print_(format(item, format))
TypeError: 'unicode' object is not callable

willgrnr avatar Feb 03 '15 06:02 willgrnr

@brunal, can you please take a look at this if you get back from holiday before I get to it? Seems related to #1269.

sampsyo avatar Feb 03 '15 06:02 sampsyo

This is caused by _process_item in duplicates.py having an argument named format, which shadows the function format responsible for actually formatting. Resulting in:

format = '' # passed from function argument
# ...function logic...
print_(format(item, format)) # format is unicode, crash

So it's easily fixed by renaming the argument to fmt (as its been done in other places). I guess this one was just overlooked with the big refactoring.

tomjaspers avatar Feb 03 '15 12:02 tomjaspers

Excellent; looks right to me. @willgrnr, can you confirm that this is fixed now?

sampsyo avatar Feb 03 '15 17:02 sampsyo

By the way, the convert plugin uses format as an argument / variable all over the place too (used to indicate fileformat of items). I'm not sure if this is problematic already, but it's probably asking for trouble with the shadowing, so guess it wouldnt hurt to refactor it to something like fileformat.

tomjaspers avatar Feb 03 '15 18:02 tomjaspers

@sampsyo @tomjaspers everything looks good from my end, thanks a bunch!

willgrnr avatar Feb 03 '15 18:02 willgrnr

Yeah, that could get a little weird. I'm not opposed to shadowing built-ins like this in general, it has so far burned us once. Maybe like path_format would be a good general recommendation in the future.

sampsyo avatar Feb 03 '15 19:02 sampsyo

Small 1-commit PR that deletes remaining format usages as a variable.

brunal avatar Feb 11 '15 15:02 brunal