News for hackers. Stuff that matters.
Re:Show HN: Forbidden Fruit – Patch built-in Python objects by herge on Wednesday April 03, 2013 @02:57PM (#5488257)
Man, having this as a context manager (maybe with the help of contextlib) would be great, because context managers are great.
Re:Show HN: Forbidden Fruit – Patch built-in Python objects by clarete on Wednesday April 03, 2013 @03:18PM (#5488380)
That's the idea. Everything to make testing easier! :)
Re:Show HN: Forbidden Fruit – Patch built-in Python objects by jacobolus on Wednesday April 03, 2013 @03:35PM (#5488475)
What are the license implications of using GPLv3 code as part of a test suite?
Re:Show HN: Forbidden Fruit – Patch built-in Python objects by clarete on Wednesday April 03, 2013 @03:45PM (#5488530)
I don't think that there's any implications for that, but I'll probably relicense this library as MIT or at least LGPL pretty soon.

I just used my default licence template, which defaults to GPL.

Re:Show HN: Forbidden Fruit – Patch built-in Python objects by marcosmlopes on Wednesday April 03, 2013 @04:31PM (#5488843)
Wow! Great news. It would be nice have this project under MIT license.
Re:Show HN: Forbidden Fruit – Patch built-in Python objects by pekk on Wednesday April 03, 2013 @03:31PM (#5488463)
If you are doing this for testing, it's already a feature of pytest: http://pytest.org/latest/monkeypatch.html
Re:Show HN: Forbidden Fruit – Patch built-in Python objects by clarete on Wednesday April 03, 2013 @03:44PM (#5488524)
I might be wrong, but I don't think that it's actually possible to mock built-in objects (written in C, not in python) using pytest.

A very quick test would be trying to do something like this:

>>> monkeypatch(str, "blah", "bleh") >>> assert str.blah == "bleh"

I tried it here with no success though.

Re:Show HN: Forbidden Fruit – Patch built-in Python objects by oellegaard on Wednesday April 03, 2013 @03:40PM (#5488499)
While it is a cool project, I hope I never have to work on a project that use this. I hate when people overwrite built-ins, but that might just be me.
Re:Show HN: Forbidden Fruit – Patch built-in Python objects by tekacs on Wednesday April 03, 2013 @06:07PM (#5489532)
Particularly striking is how little (pure Python) code was required to do this (courtesy ctypes)!

A wonderful hack! :)

Edit: see https://github.com/clarete/forbiddenfruit/blob/master/forbid...

Re:Show HN: Forbidden Fruit – Patch built-in Python objects by daGrevis on Thursday April 04, 2013 @04:12AM (#5491549)
Look good! I would like to see more examples of how to use it in tests tho!
Re:Show HN: Forbidden Fruit – Patch built-in Python objects by hcarvalhoalves on Wednesday April 03, 2013 @03:19PM (#5488384)
What's the use case?
Re:Show HN: Forbidden Fruit – Patch built-in Python objects by clarete on Wednesday April 03, 2013 @03:23PM (#5488406)
I have two main use cases in my mind right now.

1) Making it easier to write tools for testing python code, like sure[0] and freezegun[1]

2) Prototyping new features for python without touching the C code.

[0] http://github.com/gabrielfalcao/sure -- where forbiddenfruit started) [1] http://github.com/spulec/freezegun

Re:Show HN: Forbidden Fruit – Patch built-in Python objects by philipbjorge on Wednesday April 03, 2013 @03:27PM (#5488429)
It's a dirty hack - therefore, fun.
Re:Show HN: Forbidden Fruit – Patch built-in Python objects by prezjordan on Wednesday April 03, 2013 @06:12PM (#5489563)
Probably for the same reason why reopening Ruby classes is used so much. "hello, world".capitalize looks nicer than capitalize("hello, world"), and it's more convenient for method chaining.
Re:Show HN: Forbidden Fruit – Patch built-in Python objects by shabble on Wednesday April 03, 2013 @11:16PM (#5490770)