Replies: 3 comments 4 replies
-
|
I think |
Beta Was this translation helpful? Give feedback.
-
|
@erictraut Mark isn't actively working on Pyre anymore, so I can step in for PEP 612 related questions.
This implies that we need to leave out the class _lru_cache_wrapper(Generic[_P, _T]):
def __call__(*args: _P.args, **kwargs: _P.kwargs) -> _T: ...The following code works in Pyre (you'd have to change If that sounds reasonable, we can probably update the PEP (along with a couple of clarifications that others had brought up). |
Beta Was this translation helpful? Give feedback.
-
|
There is a similar issue that it appears involves the same problem, in this PR: python/typeshed#6670 The thing is, removing It seems like it'd be cool to have some kind of a descriptor type, that'd handle inserting the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm a contributor to pyright, and I'm hoping to get some clarification about a particular use case involving ParamSpec (introduced in PEP 612) and
__call__methods.Consider the following code, which executes with no runtime exceptions.
The
functools.cachedecorator is defined in typeshed'sfunctools.pyias follows:And
_lru_cache_wrapperis defined as:When the
@cachedecorator is applied to the methodcached, the ParamSpec_Pcaptures the input parameters ofcached. In other words, it captures the parameter list(self). The type of parameterselfin this case is implied to beFooor some subclass thereof (or if we adopt the terminology in draft PEP 637, its type isSelforSelf@Foo).The decorated type of
cachedis now_lru_cache_wrapper[(self: Self@Foo), int]. The__call__method for this specialized class is effectively now typed as:For the call expression
foo.cached()in the sample above, it appears that there is a missing argument (the one corresponding to the secondSelf@Fooparameter). Pyright therefore generates an error in this case, but clearly this isn't an error at runtime.How do we avoid a false positive error in this case?
Have the authors of PEP 612 have considered this situation? If so, what is the solution? I haven't found anything in the PEP that describes the intended behavior.
Perhaps this is just the consequence of the
functools.cachestub definition, which is attempting to model the runtime behavior but is in effect "lying" about some of the details? In that case, is there a better way to definefunctools.cacheand similar decorators? Maybe through a use of descriptor?Beta Was this translation helpful? Give feedback.
All reactions