You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By nature, Python objects do not determine their instance attributes until runtime.
For example, a pandas.DataFrame reads a file at runtime and generates attributes.
Currently Erg provides __getattribute__ to access such dynamically generated attributes, but type information is lost.
By adding the GetAttribute trait, we allow customization of dot access. Of course, this is not recommended, but may be necessary for Python API static typing.
"""This trait permits override of dot access.Unless you are a developer of a library, you should not use this."""GetAttribute=Trait {
""" When attribute resolution fails, Erg attempts to derive the attribute type using this function if the target type implements Dot. """GetAttributeType: (Attr: Str) ->TypeorNoneType
}
C=Class()
C|<: GetAttribute|.
GetAttributeTypeAttr=matchAttr:
"foo"->Int_->NoneC.
bar=1__getattribute__(self, attr) =ifattr=="foo", do:
C.__getattribute__::return1super().__getattribute__(attr)
c=C.new()
assertc.bar==1assertc.foo==1
Once GetAttribute and compile-time functions are implemented, it will be possible:
By nature, Python objects do not determine their instance attributes until runtime.
For example, a
pandas.DataFrame
reads a file at runtime and generates attributes.Currently Erg provides
__getattribute__
to access such dynamically generated attributes, but type information is lost.By adding the
GetAttribute
trait, we allow customization of dot access. Of course, this is not recommended, but may be necessary for Python API static typing.Once
GetAttribute
and compile-time functions are implemented, it will be possible:The text was updated successfully, but these errors were encountered: