Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial prototype of decorator is in progress #175

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

lukesmurray
Copy link
Collaborator

@lukesmurray lukesmurray commented May 25, 2019

These are the initial semantics.

Getter Format

get {ClassName}.{PropertyName}\t{value}

Setter Format

set {ClassName}.{PropertyName}\t{oldValue} -> {newValue}

We do not log access for any properties whose name starts with underscore since these are "hidden".

We do not log anything which is touched while accessing the initial property. A simple example of when this occurs is Message.sender. Our code for Message.sender returns Message.from_. Without hiding nested logs we would log a getter for Message.sender and a getter for Message.from_. With the hiding we only log a getter for Message.sender.

Here is some code and an example of the output which looks good.

def on_message(my_message):
    my_message.subject
    my_message.sender
    my_message.deadline = datetime.now()

output

get Message.subject Testing Email 😎Yeet
get Message.sender lukemurraytest@gmail.com
set Message.deadline None -> 2019-05-25 17:08:53.215517

Now consider the following example. We have one line but we get two lines of logged output. This is because we are accessing two properties in a row. First we get the sender then we get the name. @soyapark maybe you have some insight about what we want to do here.

def on_message(my_message):
    my_message.sender.name

output

get Message.sender lukemurraytest@gmail.com
get Contact.name luke murray

Right now these features are only implemented in the simulation code not in the regular interpret code.

The current state of the code for this feature is very poor but the semantics are interesting.

@lukesmurray lukesmurray mentioned this pull request May 25, 2019
@lukesmurray lukesmurray requested a review from soyapark May 25, 2019 21:23
@lukesmurray
Copy link
Collaborator Author

fixes #122

@lukesmurray
Copy link
Collaborator Author

Also added the ability to get the name of attachment files without downloading any data. message.attachments return a list of all the attached files.

fixes #125

@soyapark
Copy link
Member

Now consider the following example. We have one line but we get two lines of logged output. This is because we are accessing two properties in a row. First we get the sender then we get the name. @soyapark maybe you have some insight about what we want to do here.

def on_message(my_message):
my_message.sender.name

hmm interesting! I think it would be nice to print out only the last results, but show the rest of traces if users want to see them i.e. we can fold the rest and users can expand it.

Copy link
Member

@soyapark soyapark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great overall! Didn't imagine this could be this simple & clean. Just left a few comments & suggestion

return False

class CustomProperty(object):
"Emulate PyProperty_Type() in Objects/descrobject.c"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a comment?

c=class_name, p=property_name, v=value)
_set_in_log(obj, False)

if not property_name.startswith("_"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this if statement right after property_name = _get_method_name(self.fget) so we can do early-exit?

self.fset(obj, new_value)
_set_in_log(obj, False)

if not property_name.startswith("_"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repeating: Can we move this if statement right after property_name = _get_method_name(self.fget) so we can do early-exit?

_get_logger().critical("HEEEEEEEEEEERE")
user_property_log = obj._imap_client.user_property_log
user_property_log.write(info)
user_property_log.write(u"\n")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we are just appending logs in one string object. Can we make it more parse-able? Can we include additional information which line of user's code this property log generated from? For example,

def on_message(my_message):
    if '😎' in my_message.subject and 'Luke Murray' == my_message.sender:
        my_message.deadline = datetime.now()

this will be

{ 2: [{'type': 'get', 'log': 'Message.subject	Testing Email 😎Yee'}, {'type': 'get', 'log': 'Message.sender lukemurraytest@gmail.com'}]
  3: [{'type': 'set', 'log': 'Message.deadline	None -> 2019-05-25 17:08:53.215517'}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants