Please ignore secret bonuses. Secret tests do NOT award bonus. Max hw grade is 30+2 bonus efficiency

Do you need help?

Failing test_zz_top_types to TypeError

Julio Zenelaj (3190 points)
1 8 32
in HW4 by (3.2k points)
edited by
Hello!
When testing my HW4 program, I am getting a strange error in the testcase test_zz_top_types which is: TypeError: type of the return value must be str; got list instead.

The main function of my program is structured in this way: return B(A(filename)), where A() returns a list of strings found in the files and B() generates the final string from the list based on the rules of the homework. Strangely enough, the testcase mentioned above seems to get as a result the return value of A() and doesn't pass it through B(). It is not that the testcase calls A() directly, it calls the main function which I described above and it should have received the final string instead of the list of strings.

When tested manually, the program gives the proper output for the input 'test01/A.txt' but this doesn't happen in the test, despite the same input.

If any of the professors could look into the case, I would appreciate it a lot.

UPDATE: I merged A() into the main function and it works now. Apparently, the function picks the first thing that is returned in the whole program, instead of what the main function returns eventually. I believe that this should be changed in future homework as it goes against the expected logical flow of a program and discourages better organization of code.
249 views

2 Answers

e
enricomaria.follega (1460 points)
9 18 29
by (1.5k points)
Strange yes.

It should return the result of B. if function B is correct so should be also the test.

test manually again trying to assign A() to a variable, print that variable, and do the same for B() then return b_variable.

in this way you can double check that it is actually doing what it's supposed to do, and you avoid that VM could pick A() instead.

just like so:

a_variable = A(filename)

print(a_variable)

b_variable = B(a_variable)

print(b_variable)

return b_variable

than try to submit it to the VM. Remember to comment print.
Julio Zenelaj (3190 points)
1 8 32
by (3.2k points)
I just tried that and the issue persists. Thank you for your suggestion anyways!
Cigo (5050 points)
3 6 48
by (5.1k points)

I see you solved, but I still find interesting why your old solution did not work.

I divided my code in 4 functions, and all of them return something. But if it stops, as you said, after the first return, I would get your same error.

It may be something strange happening with the test file, but probably you already tried to re-download it, and by changing and merging inside the main function you passed the test, so it should not be related to it.

You could try, to avoid merging A into the main function that increases intricacy, to return from the main function in this way:

  • Instead of doing...
    def most_frequent_chars(filename):
        return B(A(filename))
  • ...try with
    def most_frequent_chars(filename):
        final_string = B(A(filename))
        return final_string

It should be the same actually, but I don't know, this is the only thing that came up to my mind trying to unravel the mystery :)

Julio Zenelaj (3190 points)
1 8 32
by (3.2k points)
I did try those suggestions but they didn't work.

How many functions return in most_frequent_chars for you? I wonder if the first function returning something into the main function is what stops the program. Because I also had a C function that returns into B but that didn't do anything (even though, now that I am thinking, the program didn't get into B at all, so of course it would never reach C).
e
enricomaria.follega (1460 points)
9 18 29
by (1.5k points)

ahahah that's why then :D.

good job! yes

Cigo (5050 points)
3 6 48
by (5.1k points)

I wonder how your program never gets into B if you're calling it from the main function.

By the way, if for first function you mean the one at the top, that function is called many times in my main functions, and the others too. 

In my main function there's only one return, that's the final one, but there are multiple function calls, that of course will return something.