Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #81582

Re: bug or feature in enum34 py2.7 backport?

Newsgroups comp.lang.python
Date 2014-11-26 07:14 -0800
References <1b49aa55-ba5f-4e70-8ddb-ae5dea3a40da@googlegroups.com> <1417010748.2940071.195658861.2859C26B@webmail.messagingengine.com> <mailman.16324.1417012836.18130.python-list@python.org>
Message-ID <bad44c48-3592-4c9b-ba97-a6f19e30f95d@googlegroups.com> (permalink)
Subject Re: bug or feature in enum34 py2.7 backport?
From Mark Summerfield <list@qtrac.plus.com>

Show all headers | View raw


I only mentioned it since I noticed it. I actually use Python 3 so it isn't a problem for me, but sometimes I have to teach Python 2.7 and I wanted to cover enum because it is so much nicer and easier to debug than FOO = 1 etc.

However, the problem is that enum's function API doesn't play nicely with unicode literals. One solution is to use the class API instead:


from __future__ import print_function
from __future__ import unicode_literals
import enum
print(enum.version)
class A(enum.Enum):
   b = 1
   c = 2
print(A.b, A.c) 


On Wednesday, November 26, 2014 2:41:16 PM UTC, Chris Angelico wrote:
> On Thu, Nov 27, 2014 at 1:05 AM,  <fastmail.us> wrote:
> > On Wed, Nov 26, 2014, at 06:29, Mark Summerfield wrote:
> >> TypeError: type() argument 1 must be string, not unicode
> >
> > If this is a bug, maybe it is one in type() itself - I get the same
> > error with type('X', (object,), dict(a=1))
> 
> I'd say that's a limitation, not a bug. A lot of stuff in Python 2
> depends on identifiers being ASCII-only byte strings, including -
> apparently - parts of the core code. Suggestion: Switch to Python 3,
> or if you can't do that, pass your identifiers through str(). When you
> do eventually switch to Py3, that won't do anything, but in Py2, it'll
> force them to be byte strings. As long as they are actually
> ASCII-only, that'll solve your problem.
> 
> ChrisA

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

bug or feature in enum34 py2.7 backport? Mark Summerfield <list@qtrac.plus.com> - 2014-11-26 03:29 -0800
  Re: bug or feature in enum34 py2.7 backport? random832@fastmail.us - 2014-11-26 09:05 -0500
  Re: bug or feature in enum34 py2.7 backport? Chris Angelico <rosuav@gmail.com> - 2014-11-27 01:40 +1100
    Re: bug or feature in enum34 py2.7 backport? Mark Summerfield <list@qtrac.plus.com> - 2014-11-26 07:14 -0800
      Re: bug or feature in enum34 py2.7 backport? Chris Angelico <rosuav@gmail.com> - 2014-11-27 02:17 +1100
  Re: bug or feature in enum34 py2.7 backport? random832@fastmail.us - 2014-11-26 10:32 -0500
  Re: bug or feature in enum34 py2.7 backport? Chris Angelico <rosuav@gmail.com> - 2014-11-27 02:46 +1100
  Re: bug or feature in enum34 py2.7 backport? Ethan Furman <ethan@stoneleaf.us> - 2014-11-26 08:58 -0800
  Re: bug or feature in enum34 py2.7 backport? Terry Reedy <tjreedy@udel.edu> - 2014-11-26 16:16 -0500

csiph-web