Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How do I type an overloaded function's keyword arguments that may not be specified?#1919

Unanswered
cjw296 asked this question inQ&A
Discussion options

Hand-waving, I have this:

classMockDateTime:@overload@classmethoddefset(cls,year:int,month:int,day:int,hour:int= ...,minute:int= ...,second:int= ...,microsecond:int= ...,tzinfo:TZInfo= ...,    )->None:        ...@overload@classmethoddefset(cls,instance:datetime,/    )->None:        ...@classmethoddefset(cls,*args:int|datetime,**kw:int)->None:"""        This will set the :class:`datetime.datetime` created from the        supplied parameters as the next datetime to be returned by        :meth:`~MockDateTime.now` or :meth:`~MockDateTime.utcnow`, clearing out        any datetimes in the queue.  An instance        of :class:`~datetime.datetime` may also be passed as a single        positional argument.        """

So, those ellipsis make mypy unhappy, but how do I express "these may not be present, but if they are, they must be ints, or TZInfo in the case oftzinfo"?

Note, this is explicitlynot what I want, since it's not valid to pass None for these:

classMockDateTime:@overload@classmethoddefset(cls,year:int,month:int,day:int,hour:int=None,minute:int=None,second:int=None,microsecond:int=None,tzinfo:TZInfo=None,    )->None:        ...
You must be logged in to vote

Replies: 1 comment

Comment options

See#2040 for newer discussion on this.

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
1 participant
@cjw296

[8]ページ先頭

©2009-2025 Movatter.jp