Questions tagged [forbiddenfruit]

forbiddenfruit is a Python library that allows patching built in objects

The forbiddenfruit project allows you to patch built-in objects, declared in C through python.

6 questions
57
votes
5 answers

Extension method for python built-in types

is it possible to add extension method to python built-in types? I know that I can add extension method to defined type by simply adding new method by . as following: class myClass: pass myClass.myExtensionMethod = lambda self,x:x * 2 z =…
Saeed Afshari
  • 939
  • 1
  • 9
  • 17
10
votes
1 answer

Python overload primitives

I'm trying to overload some methods of the string builtin. I know there is no really legitimate use-case for this, but the behavior still bugs me so I would like to get an explanation of what is happening here: Using Python2, and the forbiddenfruit…
Centime
  • 113
  • 6
6
votes
1 answer

Make int iterable with forbiddenfruit

I know, this is wrong, but is it possible? I thought an object is considered an iterable when its .__iter__ method returned an iterator? So why doesn't this work? >>> from forbiddenfruit import curse >>> def __iter__(self): ... for i in…
L3viathan
  • 26,748
  • 2
  • 58
  • 81
1
vote
3 answers

Check if string contains any string in list with forbiddenfruit

Suppose I want to check if a string contains any string in a list. One way to do this is word = 'hello world' any(substring in word for substring in ['hello','apple']) although this seems a bit verbose to me. Ideally I…
user10400458
0
votes
0 answers

Forbiddenfruit Visual C++ 14.0 required

I'm currently writing a localize method for my program and I'm currently coding on Mac OS X and the Forbiddenfruit library works finely. But when I tried to run it in Windows 10 computer it causes an exception. There are 4 questions I can't stop…
0
votes
1 answer

Is it possible to monkey-patch a built-in class in Jython?

After discovering forbidden fruit, a CPython package that made me stare in shear horror as I observed unholy desecration of Python's sacred built-in classes, I was wondering if such a thing could be/has been done in Jython too? For instance, do…
Liam Deacon
  • 904
  • 1
  • 9
  • 25