Use BaseTzInfo as base class for all objects

Bug #1696956 reported by Peter Bex
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
pytz
Fix Released
Medium
Stuart Bishop

Bug Description

I'm trying to use pytz objects in combination with psycopg2. In order to automatically convert objects in query parameters, one can register a so called adapter.

Psycopg2 detects which type something is from its class, and uses isinstance to match it up with the registered adapter for that type.

I tried registering an adapter for pytz.tzinfo.BaseTzInfo, but then immediately noticed that pytz.UTC is not a subclass of BaseTzInfo, but only of datetime.tzinfo. This poses a problem, because while all the things returned by pytz.timezone() have a "zone" attribute for retrieving the name of the timezone, datetime.tzinfo has no documented way of doing the same.

To avoid this, I now have to register both an adapter for type(pytz.UTC) (because it's a singleton and not a class, I have to use type()) _and_ for pytz.tzinfo.BaseTzInfo.

For information on adapting type in psycopg2, see http://pythonhosted.org/psycopg2/advanced.html#adapting-new-types

Revision history for this message
Stuart Bishop (stub) wrote :

A common base class is certainly possible, and BaseTzInfo is likely the best candidate.

Changed in pytz:
status: New → Triaged
importance: Undecided → Medium
Revision history for this message
Jens Troeger (jens.troeger) wrote :

@Stuart, any idea when this bug might be addressed?

Stuart Bishop (stub)
Changed in pytz:
status: Triaged → In Progress
assignee: nobody → Stuart Bishop (stub)
Stuart Bishop (stub)
Changed in pytz:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.