Re: __unicodeConvert and sub-classing unicode

Nicola Larosa <[email protected]> Wed, 27 Oct 2004 08:27:30 +0200
Newsgroups gmane.comp.python.db.pypgsql.user
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[Disclaimer: not an official response, just some bystander who happens to have 
delved deep into the code of pyPgSQL, while resisting the urge to fork 
it. ;-) ]


> I've experimented with hacking PgSQL.py to use isinstance() in the 
> various places instead.  ie. Instead of:
> 
>  if type(obj) is UnicodeType:
>   do_something()

This way of checking types is deprecated, exactly because of the problem you 
encountered.


> I've changed it to:
> 
>  if isinstance(obj, UnicodeType):
>   do_something()

This is how it's supposed to be done, at this moment.


> In my case at least, this appears to fix things, but I haven't tested it 
> intensively.
> 
> I realise that sub-classing 'str' and 'unicode' isn't a normal thing for 
> most people to do.

You are definitely supposed to be able to do that.


> Is that the only reason that the 'is' operator was used, or is it more
> complicated than that? 

Just historical reasons, probably.


> If someone who better understands the inner workings of pyPgSQL could 
> clarify it for me, I'd appreciate it.  Otherwise I'll go ahead and 
> report it as a bug.

I'm not claiming to be an expert, but I didn't see anything in the code that 
needs the original unicode type, and nothing else. So yes, you should go 
ahead, IMO.


- -- 
Nicola Larosa - nico-kqPTfkfBL9/[email protected]

Unchecked police and military power undermine personal security,
and increase the risk of terrorism attacks. Unchecked terrorism only
increases the risk of terrorism attacks. Statistically, if both are
possible, I am more at risk from the first, and am likely to lose more.
 -- Daniel Staal, August 2004

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iD8DBQFBfz/VXv0hgDImBm4RAhi5AKCAYlHCdAdirtQJRcjhGRlTYxtfFACgg5Ay
748fHMKPiUtq50djdy7gtbI=
=4piy
-----END PGP SIGNATURE-----


-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click