Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'attribute': 0.05; 'attributes': 0.07; 'python': 0.09; '(without': 0.09; 'it;': 0.09; 'methods,': 0.09; 'separately': 0.09; 'subject:Why': 0.09; 'programmer': 0.11; 'subject:not': 0.11; 'represents': 0.15; 'sat,': 0.15; 'class),': 0.16; 'combinations': 0.16; 'distinct': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'naive': 0.16; 'roy': 0.16; 'values),': 0.16; 'wrote:': 0.17; 'integer': 0.17; '(or': 0.18; 'module': 0.19; 'defined': 0.22; 'errors': 0.23; "i've": 0.23; 'raise': 0.24; 'header:In-Reply- To:1': 0.25; 'common': 0.26; 'values': 0.26; 'am,': 0.27; 'implemented': 0.27; 'separate': 0.27; 'question': 0.27; 'message- id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'all.': 0.28; 'represent': 0.28; 'methods.': 0.29; 'things,': 0.29; 'though.': 0.29; 'class': 0.29; 'classes': 0.30; 'e.g.': 0.30; 'fri,': 0.30; 'could': 0.32; 'certain': 0.33; "aren't": 0.33; 'to:addr:python- list': 0.33; 'operations': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'so,': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'does': 0.37; 'why': 0.37; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'positive': 0.38; 'fact': 0.38; 'mean': 0.38; 'speak': 0.38; 'gives': 0.39; 'to:addr:python.org': 0.39; 'where': 0.40; 'skip:u 10': 0.60; 'most': 0.61; 'share': 0.61; 'between': 0.63; 'different': 0.63; 'more': 0.63; 'obvious': 0.71; 'smith': 0.71; '(based': 0.84; '2013': 0.84; 'hardly': 0.84; 'notion': 0.84; 'instant': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=BsGYXICO1xt5GJMnwaKdZWzMd8yigQ6CZz8DyXSOnr4=; b=oGKm9HytjqAJrxrI707nrdo/mrw/XMGCuoVz6UUlDLct1w5Ac3B8K56c2ddwB4ESy6 jCFC2aXJ0Tw/ToR5va+BTRNt+Qt1sj98xqKGxqTD2eN5SAG5wNnRutJ+Ju7uXxgDSay4 BPnrgNVN7deYv5DMqA5Gs61ucYTzQnoHWgZ6WjghDdiF57XY6aVPnWSO0W9+PcJ4OoyO 3euYPjgmudSMWBZj7gxGY6lNFrs02DYWt/iWXWwKvU/pR9kAWDs1VqN8l9bgnfBHq1xy Nzmmu1Lqzr2hMKnZNYwO6w8pziYekJ7lEEzB7mJHm+z4povjmxa1AHCvco2cU94IJ+O6 LkPQ== MIME-Version: 1.0 X-Received: by 10.68.8.69 with SMTP id p5mr5729646pba.212.1362780077957; Fri, 08 Mar 2013 14:01:17 -0800 (PST) In-Reply-To: References: Date: Sat, 9 Mar 2013 09:01:17 +1100 Subject: Re: Why are timezone aware and naive datetimes not distinct classes? From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1362780081 news.xs4all.nl 6934 [2001:888:2000:d::a6]:40277 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:40907 On Sat, Mar 9, 2013 at 8:33 AM, Nobody wrote: > On Fri, 08 Mar 2013 13:41:27 -0500, Roy Smith wrote: > >> So, the question is, WHY aren't aware and naive datetimes separate >> classes? They share many attributes and methods, but not all. > > They share all attributes and methods. > > You could just as well ask why positive and negative floats aren't > separate classes (based upon the fact that e.g. math.sqrt() and math.log() > raise domain errors for negative floats). > > Just because certain operations aren't defined for all values (or all > combinations of values), that doesn't make the values where those > operations aren't defined into a distinct type. They represent different things, though. A naive datetime is kinda like an integer - an abstract thing that has meaning only as the programmer gives it meaning; an aware datetime unambiguously represents an instant in time. SQL has completely different data types for "TIMESTAMP WITHOUT TIME ZONE" and "TIMESTAMP WITH TIME ZONE". As I see it, a naive datetime simply does not have a timezone. The fact that it may have an attribute that's set to None doesn't mean that it "shares all attributes" with aware datetimes; if they were implemented completely separately (without even a common base class), the most obvious difference would be the complete absence of timezone attribute on the naive type. Conceptually, Roy's notion of a common base class makes good sense. But I can't speak for the Python datetime module as I've hardly used it; there may be practical considerations that mean the current model works better. All I can say is, there's definitely more difference between aware and naive datetimes than there is between positive and negative floats. ChrisA