These are chat archives for pybee/general

4th
Mar 2017
Deepanshu Thakur
@Deepanshu2017
Mar 04 2017 00:11
@freakboy3742 I see an interesting thing. Some method are calling some Exception with plain strings while some methods are calling same Exceptions with String objects. Is it intentional?
Russell Keith-Magee
@freakboy3742
Mar 04 2017 00:12
Yes - it’s a shortcut.
Deepanshu Thakur
@Deepanshu2017
Mar 04 2017 00:13
That's okay because I was testing something and found this.
Russell Keith-Magee
@freakboy3742
Mar 04 2017 00:13
If you’re just throwing an exception ,and you know what the error message should be, you can save a few cycles by just using the Java string directly, rather than constructing a Python String object and then just calling toString on it.
Deepanshu Thakur
@Deepanshu2017
Mar 04 2017 00:14
So in my patch should I add another constructor with Java Strings ?
in that way say for ValueError we will have 4 constructors

If you’re just throwing an exception ,and you know what the error message should be, you can save a few cycles by just using the Java string directly, rather than constructing a Python String object and then just calling toString on it.

Right.

Russell Keith-Magee
@freakboy3742
Mar 04 2017 00:26
Correct. The one that is missing would be the one that matches the Python prototype an org.python.Object, and be annotated so that is what VOC sees.
Deepanshu Thakur
@Deepanshu2017
Mar 04 2017 00:27
yes exactly
Russell Keith-Magee
@freakboy3742
Mar 04 2017 00:27
So it’s not just a single argument -
In [1]: ValueError?
Init signature: ValueError(self, /, *args, **kwargs)
Docstring:      Inappropriate argument value (of correct type).
Type:           type

In [2]: ValueError(1,2,3)
Out[2]: ValueError(1, 2, 3)

In [3]: raise ValueError(1,2,3)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-1f28c4e5e763> in <module>()
----> 1 raise ValueError(1,2,3)

ValueError: (1, 2, 3)
Deepanshu Thakur
@Deepanshu2017
Mar 04 2017 00:32
right, right (:
Damn I think now I am doing a kind of mistake.
in this way my ValueError class will now have 5 constructors
Deepanshu Thakur
@Deepanshu2017
Mar 04 2017 00:41
For a single value simple string constructor is fine but for more than 1 value well am I going to add another constructor in every parent class for this work?
Russell Keith-Magee
@freakboy3742
Mar 04 2017 00:48
I haven’t dug into it, but quite possibly.
But you shouldn’t need 5 constructors - just one that takes (*args, **kwargs), like the ValueErrorprototype requires.
which will catch the “single string argument” case.
Deepanshu Thakur
@Deepanshu2017
Mar 04 2017 00:50
yep that's what I was thinking of

which will catch the “single string argument” case.

?

So concat all the args by comma separated as String and pass to parent constructor?
Russell Keith-Magee
@freakboy3742
Mar 04 2017 00:56
Not quite. Have a play with 0/1/many arguments to ValueError in a Pytho shell, and see what happens.
Deepanshu Thakur
@Deepanshu2017
Mar 04 2017 00:57
TypeError: ValueError does not take keyword arguments
Russell Keith-Magee
@freakboy3742
Mar 04 2017 00:57
That’s keyword arguments.
What about raise ValueError()? raise ValueError(1)? raise ValueError(1,2,3)
Deepanshu Thakur
@Deepanshu2017
Mar 04 2017 00:57
I see ValueError(1,)
Russell Keith-Magee
@freakboy3742
Mar 04 2017 00:58
What version of Python? That’s not what I’m seeing...
Deepanshu Thakur
@Deepanshu2017
Mar 04 2017 00:58
3.4
Russell Keith-Magee
@freakboy3742
Mar 04 2017 00:58
Huh… interesting.
That’s changed in 3.5
Or, at least, the repr has changed.
Deepanshu Thakur
@Deepanshu2017
Mar 04 2017 01:00

ValueError: 1
ValueError
ValueError: (1, 2, 3)

For raise ValueError(1), raise ValueError(0) ad ValueError(1,2,3)

Hmm sorry network issue
Are you using IronPython?
Russell Keith-Magee
@freakboy3742
Mar 04 2017 01:02
No - CPython3.5
Deepanshu Thakur
@Deepanshu2017
Mar 04 2017 01:02
because I am using default CPython
dgelessus
@dgelessus
Mar 04 2017 01:02
FWIW, repr(ValueError(1)) is "ValueError(1,)" for me on CPython 3.4, 3.5, 3.6
Russell Keith-Magee
@freakboy3742
Mar 04 2017 01:02
Huh...
Must be an iPython thing -
repr(ValueError(1)) has the comma in it, but just outputting the value doesn’t.
Ok - ignore that quirk, then.
dgelessus
@dgelessus
Mar 04 2017 01:03
Oh, yeah. IPython's display for it has no extra comma.
Russell Keith-Magee
@freakboy3742
Mar 04 2017 01:03
But, do note the difference between repr and str output.
dgelessus
@dgelessus
Mar 04 2017 01:04
Right, the str is what lands in the exception message in the traceback
Deepanshu Thakur
@Deepanshu2017
Mar 04 2017 01:04
yes
str(ValueError(1)) -> 1
repr(ValueError(1)) -> ValueError(1,)
dgelessus
@dgelessus
Mar 04 2017 01:06
It looks like the exception str and repr is inherited from BaseException, which probably just uses the args attribute.
Deepanshu Thakur
@Deepanshu2017
Mar 04 2017 01:07
Ahh where we were initially? The constructor thing. I think I will use that (*args, **kwargs) to convert that into comma separated string to pass to BaseException
dgelessus
@dgelessus
Mar 04 2017 01:08
In CPython, BaseException takes any number of arguments, and puts them into the exception's args attribute
The conversion to string only happens once str or repr is called.
Deepanshu Thakur
@Deepanshu2017
Mar 04 2017 01:11

The conversion to string only happens once str or repr is called.

Ahh right.

dgelessus
@dgelessus
Mar 04 2017 01:13
Of course, the most common cases in practice are no arguments, a single string, or a single object. Multiple exception arguments are not very common.
Deepanshu Thakur
@Deepanshu2017
Mar 04 2017 01:16
Okay I tried that args, kwargs thing but Java doesn't seem to accept only args arguments
And that should be the case with existing constructors too.
Chiang Fong Lee
@cflee
Mar 04 2017 04:42
hmm, I’m reworking my very old pybee/voc#122, getting stuck encoding a if (a || b) statement using the IF() pseudoinstructions
I know what the generated Java bytecode should look like, but there doesn’t seem to be a nice way using IF()/ELIF()/ELSE()/END_IF() to let both a and b jump to the same place
leasunhy
@leasunhy
Mar 04 2017 07:42
@freakboy3742 VOC pr pybee/voc#383 and pybee/voc#363 are ready for review. Thank you!
Deepanshu Thakur
@Deepanshu2017
Mar 04 2017 07:44
@leasunhy How do you analyse java bytecode?
leasunhy
@leasunhy
Mar 04 2017 07:45
@Deepanshu2017 I simply run javap -c $classname | less to disassemble the class file ;-)
Deepanshu Thakur
@Deepanshu2017
Mar 04 2017 07:46
yes thank you :)
leasunhy
@leasunhy
Mar 04 2017 07:46
you're welcome~
Chiang Fong Lee
@cflee
Mar 04 2017 07:47
@leasunhy re pybee/voc#383: methods like __add__() should return the NotImplemented singleton instead of throwing the NotImplementedError exception
so actually it won’t be a try-catch, it will be a much simpler if-else
If one of those methods does not support the operation with the supplied arguments, it should return NotImplemented.
also there is some more logic regarding subclasses.
Note: If the right operand’s type is a subclass of the left operand’s type and that subclass provides the reflected method for the operation, this method will be called before the left operand’s non-reflected method. This behavior allows subclasses to override their ancestors’ operations.
leasunhy
@leasunhy
Mar 04 2017 07:50
ah, didn't read about that @cflee
the logic will be several lines of jave code and tens of lines of bytecode... and that's what exactly leading to code bloat ;-)
I will go to update the comment in my pr soon
Chiang Fong Lee
@cflee
Mar 04 2017 07:52
i’m not really sure how this is code bloat. usually that refers to the (human?) programmer having to write a lot of code right? there’s no impact on the python code
code bloat is more related to generated code, which is a common concern with C++ template
Chiang Fong Lee
@cflee
Mar 04 2017 07:54
yes. but on the JVM, the compiler only does a little optimization, most of it is done at runtime instead
Sarthak Suri
@SarthakSuri
Mar 04 2017 07:54
@freakboy3742 @cflee could you review pr pybee/voc#381 too
Chiang Fong Lee
@cflee
Mar 04 2017 07:55
I think it would be more interesting to see whether either approach will make the JVM be not able to do its usual optimizations, and/or benchmark the performance to demonstrate that it’s slower
Sohit
@sohit-nayak
Mar 04 2017 08:01
Hi! just created my first PR.. can someone please review pybee/voc#384 . Thanks in advance!
Saurabh--Kumar
@Saurabh--Kumar
Mar 04 2017 12:05
Screenshot from 2017-03-04 17-34-44.png
hi pybee folks. I am interested in voc project for GSOC 2017. I am trying to implement max() and min() inbuilt function. The "key" argument in both the functions is a function pointer. Java doesn't have the concept of function pointers. So what would be the type of the "key" argument in the function definition? I have written code for the case where "Key=null". The screenshot of code is above.
Dibya Prakash Das
@dibyadas
Mar 04 2017 12:11
Hi! I am Dibya Prakash Das. I absolutely love the concept of VOC and I am very interested to contribute to this project.
I have setup my environment for using voc and already tested a few programs.
I have gone through the documentation and understood almost all of it. Now all that remains is to work on the issues raised in this project and find and correct as many bugs as I can. Infact I have started working on implementing the iteration of a dict type.
Sohit
@sohit-nayak
Mar 04 2017 13:09
can anybody tell me how to use Travis CI locally?
dgelessus
@dgelessus
Mar 04 2017 13:12
Travis CI can't be run locally. But you can probably look into the .travis.yml to see what it's configured to run, and run the commands by hand.
Sohit
@sohit-nayak
Mar 04 2017 13:21
ok @dgelessus will look into it :smile:
captaincrunch21
@captaincrunch21
Mar 04 2017 13:28
ast.parse(source.read(), mode='exec') what does this line do?
dgelessus
@dgelessus
Mar 04 2017 13:37
It parses Python source code into an AST. It's explained in more detail in the ast module docs: https://docs.python.org/3/library/ast.html#ast-helpers
captaincrunch21
@captaincrunch21
Mar 04 2017 13:54
Malcolm Smith
@mhsmith
Mar 04 2017 21:16
@freakboy3742 I enjoyed your talk "A tale of two cellphones", and I've got a question about the point you made here: https://www.youtube.com/watch?v=NqdpK9KjGgQ&t=16m20s
How does it require 4,000 JNI references to run Hello World?
It looks like methods and instance variables don't require references, only objects and classes.
And even then you'd only need references to the object and classes your code actually use.