Python Forum
a feature i would like to see
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
a feature i would like to see
#1
a feature i would like to see added to Python in some future version is the ability to add methods to a builtin class and have it be automatically available to all instances and derived classes.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
It's called overriding: https://www.oreilly.com/library/view/pyt...05s02.html
Reply
#3
yes, overriding. but i'm not talking about merely doing it in an inherited class. i'm talking about retroactively applying it to an existing class with existing instances and classes inheriting from it. and i am also talking about doing this with builtin primitive classes, such as int.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
I guess you'll make Python slower if you implement this kind of feature. Exposing internal APIs is not always a good thing. People rely on that and afterwards this new feature can't be removed. Your suggestion will do also this change and afterwards you never can change it again. It's not always a good Idea. Maybe this helps you with you problem, but it may cause many other problems.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#5
yes, it would be slower. if i want speed, i'll use C (and i know C quite well). actually, i have run across many cases where i wanted to change (for that program) some existing logic.

maybe a better way would be to freeze the internal API at the major version level and allow binary modules to be loaded to hook in to internal methods. Apache has done this. my idea for a new language from many years ago was a 2 level language where there was a nearly C-like lower level and a nearly Python-like upper level (without Python's syntax which i am wanting to retrofit to both levels). maybe doing that would be better than trying to change Python (since there seems to be substantial resistance to any changes).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#6
what you want may not be wanted by 99% of other users.
If you really feel that you have something to offer, then propose to python.org through the proper channels.
Be careful, this is the best language I have ever used (with possibly the exception of forth).
Don't want to mess it up.
Reply
#7
This sounds like monkey patching. IIRC, it exists in Ruby and is one of the reasons Ruby can be terrible to use compared to Python. Python does have some monkey patching capability due to its dynamic and mutable nature, but unless you're trying to do a small, quick hack (ideally which won't be written to disk), there's a better way.
Reply
#8
so if i write some code that adds a method to a bultin type, assuming that could be done, and uses it in that code,that would be considered monkey patching?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#9
Class inheritance?
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#10
wavic, please read post 2
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020