Content-Length: 273850 | pFad | https://github.com/python/cpython/issues/126947

F6 Typecheck can be added to _pydatetime.timedelta.__new__ · Issue #126947 · python/cpython · GitHub
Skip to content

Typecheck can be added to _pydatetime.timedelta.__new__ #126947

@bombs-kim

Description

@bombs-kim

Feature or enhancement

Proposal:

It seems that a typecheck can be added as suggested by the existing comment

    def __new__(cls, days=0, seconds=0, microseconds=0,
                milliseconds=0, minutes=0, hours=0, weeks=0):
        # Doing this efficiently and accurately in C is going to be difficult
        ...

        # XXX Check that all inputs are ints or floats.

Currently, an error is raised, but it's not explicit that it's because of an argument of wrong type

_pydatetime.timedelta(seconds='1')
# TypeError: can only concatenate str (not "int") to str

If this type check is not desirable, I think we can simply remove the comment.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/python/cpython/issues/126947

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy