Skip to content

TimeDelta includes some methods that don't apply #6828

Closed

Description

@astrofrog

It looks like TimeDelta includes some methods it probably shouldn't. For example TimeDelta.now() doesn't make sense, and maybe TimeDelta.light_travel_time.

Activity

  1. mhvk commented on Nov 10, 2017

    @mhvk
    Contributor

    @taldcroft - these methods are inherited directly from Time. To avoid this, should we have a TimeBase from which both Time and TimeDelta inherit? It is rather painful in that then isinstance(..., Time) will no longer catch a TimeDelta. But I'm not sure how else to solve this.

  2. Cadair commented on Nov 11, 2017

    @Cadair
    Member

    Could some combo of ABCs and subclass hooks fix the isinstance(..., TIme) work?

  3. taldcroft commented on Nov 12, 2017

    @taldcroft
    Member

    Good point. The only question is if we are getting into "perfect is the enemy of good" territory (unless @Cadair can produce the appropriate magic).

  4. astrofrog commented on Nov 12, 2017

    @astrofrog
    MemberAuthor

    @mhvk - just to check, why should isinstance(..., Time) catch TimeDelta? Those are two quite different things, so in fact isinstance(..., Time) returning True for TimeDelta seems like a bug to me :)

  5. astrofrog commented on Nov 12, 2017

    @astrofrog
    MemberAuthor

    Just to clarify my comment, here's what I get with the datetime module:

    In [3]: from datetime import datetime
    
    In [5]: dt1 = datetime.now()
    
    In [6]: dt2 = datetime.now()
    
    In [7]: dt2 - dt1
    Out[7]: datetime.timedelta(0, 4, 731509)
    
    In [8]: isinstance(dt2 - dt1, datetime)
    Out[8]: False
    
    In [9]: isinstance(dt1, datetime)
    Out[9]: True

    There's really no reason TimeDelta should be as a subclass of Time (conceptually) so I think @mhvk's suggestion of a TimeBase makes sense.

  6. mhvk commented on Nov 12, 2017

    @mhvk
    Contributor

    @astrofrog - I agree with you that conceptually they're different and it makes sense to have a TimeBase. It is just that this may break code, as it is not how it is implemented...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions