dirtSimple.orgwhat stands in the way, becomes the way
“Monkey Typing” for Python

“Monkey Typing” for Python

I’ve just posted a partial draft of a pre-PEP proposal to add what I’m calling “monkey typing” to Python. It’s an extension of the infamous “duck typing” concept that seeks to simplify the use of interfaces in Python to the point where they scarcely exist, but are more useful than existing interface concepts for Python, including my own PyProtocols. In particular, it offers the first practical definition that I know of for a “file-like” object or a “dictionary-like” object. Check it out, then flame me for contributing to the impending ruin of the language you know and love! (Either here or on Python-Dev.)

(P.S. Since I know some of my readers are into that sort of thing, I’ll mention that “monkey typing” is either an incredibly scaled-down version of Haskell typeclasses, or a extremely agile extension of Java casting or COM QueryInterface, depending on whether you prefer Haskell, Java, or C#. But if you don’t like any of those languages, then pretend you didn’t read this P.S. and just look at the proposal anyway, as it doesn’t actually look anything at all like any of those languages, it just steals certain ideas from ’em.)

Join the discussion
  • Phillip,

    I think there’s a small semantic error in the draft:
    “In Java, for example, you say that your class…”
    should, I think, be
    “in Java, for example, you [don’t or can’t] say that your class…”

    I didn’t want to edit the wiki page, because I didn’t feel comfortable changing this.

    As for the actual content of the PEP, I think I followed you all the way to “Extenders with state”, which I really didn’t follow at all. Not sure if it’s you or me, probably somewhere in the middle.

    While I’m not ready to commit to a yay/nay decision, I will say that 1) I like it much better than guido’s static typing, 2) I like it better than pep 246, and 3) this is the first real interesting use case for decorators that I’ve seen. I saw and hated the uses of decorators for type-checking in the debate on c.l.p (@types(int, int) #blech).

  • Yes, I could definitely use something like this. It would help me to avoid a lot of Ghettoes, particularly when pulling DAOs out of a database. Rather than transfer the data to another object, I would just adapt it appropriately and use it as-is.

    (The Ghetto mini-pattern: http://fishbowl.pastiche.org/2003/05/28/the_ghetto_minipattern)

    I’ll follow this PEP with interest.

    Also, where you wrote “Extender instances can also be quite small in size, because in the general case they only need to contain a reference to the object instance that they are extending”, did you actually mean, “Extender instances can also be quite small in size, because in the typical case they only need to contain a reference to the object instance that they are extending”?



Stay In Touch

Follow our feeds or subscribe to get new articles by email on these topics:

  • RSS
  • RSS
  • RSS


Get Unstuck, FAST

Cover photo of "A Minute To Unlimit You" by PJ Eby
Skip to toolbar