- Notifications
You must be signed in to change notification settings - Fork263
-
Hi All, I eventually managed to release a simplistix/testfixtures@70283c2 I've tried to get my head around this a few times over the last few months:
I even ended up logging a ...and as well as several attempts myself, LLMs have also been struggling, even once the underlying typing was sorted out: At a high level, I'm essentially looking to revertsimplistix/testfixtures@70283c2 but with functioning type annotations, essentially providing these three calling patterns for the factory: @overloaddefmock_datetime(tzinfo:TZInfo|None=None,delta:float|None=None,delta_type:str='seconds',date_type:type[date]=date,strict:bool=False)->type[MockDateTime]: ...@overloaddefmock_datetime(year:int,month:int,day:int,hour:int= ...,minute:int= ...,second:int= ...,microsecond:int= ...,tzinfo:TZInfo|None=None,delta:float|None=None,delta_type:str='seconds',date_type:type[date]=date,strict:bool=False)->type[MockDateTime]: ...@overloaddefmock_datetime(default:datetime,tzinfo:TZInfo|None=None,delta:float|None=None,delta_type:str='seconds',date_type:type[date]=date,strict:bool=False)->type[MockDateTime]: ...@overloaddefmock_datetime(default:None,# explicit None positionaltzinfo:TZInfo|None=None,delta:float|None=None,delta_type:str='seconds',date_type:type[date]=date,strict:bool=False)->type[MockDateTime]: ...defmock_datetime(*args,tzinfo:TZInfo|None=None, ...and then these overload patterns for the methods for manipulating the queue of upcoming mock datetimes: classMockDateTime(MockedCurrent,datetime):@overload@classmethoddefadd(cls,year:int,month:int,day:int,hour:int= ...,minute:int= ...,second:int= ...,microsecond:int= ...,tzinfo:TZInfo= ..., )->None: ...@overload@classmethoddefadd(cls,instance:datetime, )->None: ...@classmethoddefadd(cls,*args,**kw):"""@@ -170,29 +147,6 @@ def add(cls, *args, **kw): """returnsuper().add(*args,**kw)@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,**kw):"""@@ -205,28 +159,6 @@ def set(cls, *args, **kw): """returnsuper().set(*args,**kw)@overload@classmethoddeftick(cls,days:float= ...,seconds:float= ...,microseconds:float= ...,milliseconds:float= ...,minutes:float= ...,hours:float= ...,weeks:float= ..., )->None: ...@overload@classmethoddeftick(cls,delta:timedelta,# can become positional-only when Python 3.8 minimum )->None: ...@classmethoddeftick(cls,*args,**kw)->None: """ ...and similar across Is Python typing just "not there yet" or am I missing something? Happy to be shown the way, ecstatic if someone feels inspired to throw up a PR 😅 |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 1 comment 2 replies
-
Can you describe the problem you're seeing in more detail? You mentioned in the other thread that the ellipses make mypy unhappy. When I paste your code into a new document, add the missing import statements, and run mypy on it, I don't see any errors. Normally, you'd need to supplyreal default argument values rather than using an ellipsis, but type checkers generally allow you to use an ellipsis as a stand-in for the actual value when you're writing overloads or stubs. It's still a good idea to provide the actual default argument values because it allows language servers to show users these values when they call the function. For example, here's what I see when I start typing a call to It would be better if you supplied the actual default values. I presume they are zero by default? If so, replace the |
BetaWas this translation helpful?Give feedback.
All reactions
-
The problems were always intractable mypy complaints of a variety of types; to reproduce: pick one of the claude or codex branches above, check it out and run I'm fine with there being no ellipsis, I wrote that years ago before I understood typing and when tools like mypy were way less mature. To be clear: the ellipsis are not the focus of the problem for me, the problem is that no human or agent that has tried can get overloads that both match the intended use semanticsand make mypy happy. |
BetaWas this translation helpful?Give feedback.
All reactions
-
You're more likely to receive answers on this forum if you can narrow the question. "I can't get this to work; can you check out my code base, grok the intent behind the code, and recommend a way to write type annotations for my library?" is pretty broad. Perhaps you could post one or two examples of an overload that youthink should work but does not? |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1