operator.isMappingType

Discussion in 'Python' started by Raymond Hettinger, Nov 2, 2003.

  1. Since the advent of extended slicing, operator.isMappingType() returns a
    misleading result.

    >>> map(operator.isMappingType, ([], (), {}, '', u''))

    [True, True, True, True, True]


    I recommend removing it from the operator module.


    Raymond Hettinger
    Raymond Hettinger, Nov 2, 2003
    #1
    1. Advertising

  2. Raymond Hettinger

    John Roth Guest

    "Raymond Hettinger" <> wrote in message
    news:vgYob.46447$...
    > Since the advent of extended slicing, operator.isMappingType() returns a
    > misleading result.
    >
    > >>> map(operator.isMappingType, ([], (), {}, '', u''))

    > [True, True, True, True, True]
    >
    >
    > I recommend removing it from the operator module.


    I get the following on 2.2.3:

    >>> map (operator.isMappingType,([], {}, (), ", u"))

    [0, 1, 0, 0]

    Where did the fifth True come from? That's really odd!

    How much code would removing it break, versus
    changing the test so it looked for one or more of the
    methods that's unique to maps, and not to other
    kinds of sequences? Granted, testing for something
    other than a magic method would slow it down, but
    that should be better than either leaving it broken,
    or breaking otherwise innocent code.

    John Roth



    >
    >
    > Raymond Hettinger
    >
    >
    John Roth, Nov 2, 2003
    #2
    1. Advertising

  3. Raymond Hettinger

    Peter Hansen Guest

    John Roth wrote:
    >
    > "Raymond Hettinger" <> wrote in message
    > news:vgYob.46447$...
    > > Since the advent of extended slicing, operator.isMappingType() returns a
    > > misleading result.
    > >
    > > >>> map(operator.isMappingType, ([], (), {}, '', u''))

    > > [True, True, True, True, True]
    > >
    > >
    > > I recommend removing it from the operator module.

    >
    > I get the following on 2.2.3:
    >
    > >>> map (operator.isMappingType,([], {}, (), ", u"))

    > [0, 1, 0, 0]
    >
    > Where did the fifth True come from? That's really odd!


    Raymond used pairs of single quotes, while you used only
    individual double-quotes surrounding a string containing
    a comma, a space, and the letter u. His had an empty
    string and an empty unicode string...

    -Peter
    Peter Hansen, Nov 2, 2003
    #3
  4. Raymond Hettinger

    John Roth Guest

    "Peter Hansen" <> wrote in message
    news:...
    > John Roth wrote:
    > >
    > > "Raymond Hettinger" <> wrote in message
    > > news:vgYob.46447$...
    > > > Since the advent of extended slicing, operator.isMappingType() returns

    a
    > > > misleading result.
    > > >
    > > > >>> map(operator.isMappingType, ([], (), {}, '', u''))
    > > > [True, True, True, True, True]
    > > >
    > > >
    > > > I recommend removing it from the operator module.

    > >
    > > I get the following on 2.2.3:
    > >
    > > >>> map (operator.isMappingType,([], {}, (), ", u"))

    > > [0, 1, 0, 0]
    > >
    > > Where did the fifth True come from? That's really odd!

    >
    > Raymond used pairs of single quotes, while you used only
    > individual double-quotes surrounding a string containing
    > a comma, a space, and the letter u. His had an empty
    > string and an empty unicode string...


    I see. That did look odd...

    John Roth
    >
    > -Peter
    John Roth, Nov 2, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jakob Bieling

    Q: operator void* or operator bool?

    Jakob Bieling, Mar 5, 2004, in forum: C++
    Replies:
    2
    Views:
    563
    Rob Williscroft
    Mar 5, 2004
  2. John Smith
    Replies:
    2
    Views:
    415
    Ivan Vecerina
    Oct 6, 2004
  3. Alex Vinokur
    Replies:
    4
    Views:
    3,036
    Peter Koch Larsen
    Nov 26, 2004
  4. Alex Vinokur
    Replies:
    3
    Views:
    5,003
    Jeff Schwab
    Mar 20, 2005
  5. Tim Clacy
    Replies:
    15
    Views:
    2,665
    Kanenas
    May 30, 2005
Loading...

Share This Page