Re: Python 3 isinstance

Discussion in 'Python' started by Lambert, David W (S&T), Jan 15, 2009.

  1. Overly terse. I do mean that this is illegal:

    isinstance(s, {str, bytes})

    tuples have order, immutability, and the possibility of repeat items.

    A set is most reasonable in a mathematical sense.
     
    Lambert, David W (S&T), Jan 15, 2009
    #1
    1. Advertising

  2. Lambert, David W (S&T)

    John Machin Guest

    On Jan 15, 2:03 pm, "Lambert, David W (S&T)" <>
    wrote:
    > Overly terse. I do mean that this is illegal:
    >
    > isinstance(s, {str, bytes})
    >
    > tuples have order, immutability, and the possibility of repeat items.


    In the anticipated/usual use case (the type/class names are hard-
    coded):
    * order is a very mild plus (you can list them in descending order of
    (imagined) probability)
    * immutability is not a problem
    * the number of items is not likely to be so large that duplicate
    entries would creep in

    > A set is most reasonable in a mathematical sense.


    This is true -- distinguishing carefully between "most reasonable" and
    "the most reasonable" :)

    Do you actually have a use case for dynamically assembling a
    collection of classes/types for use with isinstance(), or are you
    propelled solely by mathematical reasonableness?

    Cheers,
    John
     
    John Machin, Jan 15, 2009
    #2
    1. Advertising

  3. On Wed, 14 Jan 2009 22:03:37 -0500, Lambert, David W (S&T) wrote:

    > Overly terse. I do mean that this is illegal:
    >
    > isinstance(s, {str, bytes})


    *shrug*

    Just change the {} to () and it will work fine.

    Or do this:

    isinstance(s, tuple({str, bytes}))


    > tuples have order, immutability, and the possibility of repeat items.


    Yes. And why is this a problem?


    > A set is most reasonable in a mathematical sense.


    What is the benefit of using sets instead of tuples inside isinstance?





    --
    Steven
     
    Steven D'Aprano, Jan 15, 2009
    #3
    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. Joona I Palaste

    Re: isInstance problem

    Joona I Palaste, Jul 1, 2003, in forum: Java
    Replies:
    4
    Views:
    1,030
    George W. Cherry
    Jul 2, 2003
  2. Ben Jessel

    Re: isInstance problem

    Ben Jessel, Jul 10, 2003, in forum: Java
    Replies:
    0
    Views:
    396
    Ben Jessel
    Jul 10, 2003
  3. Lambert, David W (S&T)

    Python 3 isinstance

    Lambert, David W (S&T), Jan 14, 2009, in forum: Python
    Replies:
    2
    Views:
    419
    Rhamphoryncus
    Jan 16, 2009
  4. Terry Reedy

    Re: Python 3 isinstance

    Terry Reedy, Jan 15, 2009, in forum: Python
    Replies:
    4
    Views:
    1,530
    Steven D'Aprano
    Jan 16, 2009
  5. Ulrich Eckhardt

    isinstance(.., file) for Python 3

    Ulrich Eckhardt, Nov 8, 2012, in forum: Python
    Replies:
    5
    Views:
    493
    Stefan Behnel
    Nov 8, 2012
Loading...

Share This Page