-
Couldn't load subscription status.
- Fork 126
Open
Labels
Milestone
Description
I'm writing up an extension, and my wrists hurt from all the typing :) I wonder if we could use descriptors to cut down on the boilerplate. For a typical property that comes from the properties dict, it'd be something like
class MyExtension:
description = Property()where Property is a descriptor like
# untested
class Property:
def __set_name__(self, owner, name):
self.name= name
def __get__(self, obj, objtype=None):
return getattr(obj, "properties")[self.name)
def __set__(self, obj, value):
getattr(obj, "properties")[self.name] = valueI haven't really looked to see if this works for many of the extensions. Some downsides:
- Unclear how this would interact with static typing. But properties are supported by mypy, and descriptors are prosperities, so it might be doable.
- Makes
.lookup a bit slower, though on par with@propertyso maybe it's acceptable.