Fix decorators on class __init__ methods #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes a few issues around decorators, specifically resolves python#5398 and python#1706. Not sure if this is exactly the way you want to fix this. Probably better would be to get rid of the
Decorator
class altogether, but this provides a workable fix. My reasoning on it is this:Node
is callable by checking whether it is an instance ofFuncBase
.get_callable
method, which will return aFuncBase
if it makes sense to construct one for the passed inNode
, otherwise returnNone
.Node
is aFuncBase
or a callableDecorator
, but could conceivably be expanded to cover other cases with minimal additional work.Decorator
return an instance of theCallableDecorator
class, which inherits fromFuncItem
iff the decorated function is still callable.This works, but creates problems in a few places in the codebase that explicitly assume that an instance of
FuncBase
is not decorated. I have fixed the instances of this I could find, and all of the existing tests pass, but we probably want to do more testing on this to be sure.Stray observations:
property
and similar descriptor-based decorators as special cases and could work with them more directly. Possibly by having their implementations in typeshed beGeneric
s with appropriate types. This would probably require more robust type annotation than we currently support though.Var.is_staticmethod
andVar.is_classmethod
toVar.is_static
andVar.is_class
or renameFuncBase.is_static
andFuncBase.is_class
toFuncBase.is_staticmethod
andFuncBase.is_classmethod
. They duplicate the same functionality, and this would help remove some unneeded type checks in a few places.testInferListInitializedToEmptyInClassBodyAndOverriden
, but created problems in other places. This may be worth investigating further.Decorator
s that is no longer needed, but I am not familiar enough with the codebase to say that for sure.Callable
. It seems like this should be something we could determine through type inference, but I'm not sure how easy that would be to do.I look forward to your criticisms.