[Python-Dev] PyArg_ParseTuple format string: "h" vs. "H"

Guido van Rossum guido@python.org
Thu, 16 Aug 2001 13:55:52 -0400


> I was just bit by an older PyArg_ParseTuple format string behavior
> change: these days (since 2.1?) "h" barfs when you feed it an
> unsigned short value (even if it's within 16 bits). So ok, I updated
> my code to use "H" instead, only to find out hours later that "H"
> didn't exist yet in 1.5.2. I really need to be compatible with both
> so I'll have to work around it :-(
> 
> Was this change really neccesary?

Yes, the old behavior was indefensible.

Jack complained about it too, but in the end agreed he'd update his
code.

If you really want compatibility without ifdefs and don't care about
the range checks, you can use an i format and an int variable, and
cast the int to (unsigned short) when using it.

--Guido van Rossum (home page: http://www.python.org/~guido/)