nickers / tinypy

Automatically exported from code.google.com/p/tinypy
Other
0 stars 0 forks source link

empty ** arguments lead to an incorrect error message #11

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1: def foo(x, **y):
2:    print(x, y)
3: foo(1)

What is the expected output? What do you see instead?

I would expect something like: 1 {}
Instead, I get this misleading error:

File "a.py", line 3, in ?
  foo(1)
File "a.py", line 1, in foo
  def foo(x, **y):

Exception:
tp_get: KeyError: 0

What version of the product are you using? On what operating system?

Revision 29, Debian.

Please provide any additional information below.

I think I've read somewhere that you do not want to copy the Python
behavior for * and ** arguments due to added complexity, and that makes
sense - but the above case looks like an actual bug to me.

Original issue reported on code.google.com by allef...@gmail.com on 19 May 2008 at 12:09

GoogleCodeExporter commented 8 years ago
Here's a hotfix which seems to work in my project. It is still wrong, as it 
sets y to
None instead of an empty dictionary, but I can deal with that temporarily by 
checking
for None. Hopefully a real fix can be added soon. I guess it would be a matter 
of
filling in code to create a new empty dictionary instead of a None value - but 
I was
not able to figure out how to do that.

Original comment by allef...@gmail.com on 19 May 2008 at 1:12

Attachments:

GoogleCodeExporter commented 8 years ago
I think this patch would be better if:

- you had it set the destination register to a DICT so that it fixes both issues
- you create a few test cases for tests.py that demonstrate what is not 
working, so
that we have tests that prove this patch does something valuable, and so someone
doesn't revert this fix in the future.

Thanks!

Original comment by philhas...@gmail.com on 19 May 2008 at 2:37

GoogleCodeExporter commented 8 years ago
On May 19, 4:41 pm, codesite-nore...@google.com wrote:
> Issue 11: empty ** arguments lead to an incorrect error
messagehttp://code.google.com/p/tinypy/issues/detail?id=11
> 
> Comment #2 by philhassey:
> I think this patch would be better if:
> 
> - you had it set the destination register to a DICT so that it fixes
> both issues

Yeah, but I'm unable to do that, as I can't quite follow encoder.py - 
especially what
to take care off to not leak registers, so I better not touch this. I'm also not
really sure what replacing the GET with IGET did, only copied it from the
default-value-parameter case a few lines above.

> - you create a few test cases for tests.py that demonstrate what is not
> working, so
> that we have tests that prove this patch does something valuable, and
> so someone
> doesn't revert this fix in the future.

Sure, patch which adds a testcase is attached.

Original comment by allef...@gmail.com on 19 May 2008 at 8:05

Attachments:

GoogleCodeExporter commented 8 years ago

Original comment by philhas...@gmail.com on 20 May 2008 at 2:34