Weak Type Ability for Python

Peter J. Holzer hjp-python at hjp.at
Sat Apr 15 07:22:24 EDT 2023


On 2023-04-14 10:19:03 +1000, Chris Angelico wrote:
> The entire Presentation Manager and Workplace Shell (broadly
> equivalent to a Linux "desktop manager", I think? Kinda?) were object
> oriented; you would have a WPDataFile for every, well, data file, but
> some of those might be subclasses of WPDataFile. And it was fairly
> straight-forward to write your own subclass of WPDataFile, and there
> was an API to say "if you would ever create a WPDataFile, instead
> create one of my class instead". This brilliant technique allowed
> anyone to enhance the desktop in any way, quite impressive especially
> for its time. I've yearned for that ever since, in various systems,
> although I'm aware that it would make quite a mess of Python if you
> could say "class EnhancedInt(int): ..." and then "any time you would
> create an int, create an EnhancedInt instead". A bit tricky to
> implement.

Or alternatively you might be able to add or replace methods on the
existing int class. So 5 is still just an int, but now (5 + "x") calls
the modified __add__ method which knows how add a string to an int.

Might make even more of a mess ;-).

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp at hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mail.python.org/pipermail/python-list/attachments/20230415/fc257280/attachment.sig>


More information about the Python-list mailing list