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

overload print #83

Open
Almenon opened this issue Apr 13, 2019 · 3 comments
Open

overload print #83

Almenon opened this issue Apr 13, 2019 · 3 comments

Comments

@Almenon
Copy link
Owner

Almenon commented Apr 13, 2019

see Almenon/AREPL-vscode#4

from collections import Iterable
import json
import inspect
import sys

class MetaPrint:
  def __init__(self, line_num, file_name, values):
    self.line_num = line_num
    self.file_name = file_name
    self.message = values

def print_overload(*values, sep=' ', end='\n', file=sys.stdout, flush=False):
    # if print is writing to file we dont want to record metadata
    if file != sys.stdout and file != sys.stderr:
      print(values, sep, end, file, flush)
      return
  
    calling_frame = inspect.currentframe().f_back

    calling_filename = calling_frame.f_code.co_filename
    calling_lineno = calling_frame.f_lineno

    message = str(values[0] if len(values) > 0 else "")
    for val in values[1:]:
        message += sep + str(val)
  
    metaPrint = MetaPrint(calling_lineno, calling_filename, message)
    print_output(metaPrint)

# tests
print_overload()
print_overload("hello world")
print_overload("hello world", 1)
print_overload("hello world", 1, sep='-')

# assign startingLocals print to print_overload
@Almenon
Copy link
Owner Author

Almenon commented Apr 13, 2019

dependency on #61 - user should be able to choose whether they want the print overload or not.

edit: actually this isn't really a dependency - having a setting for this is a nice to have but not a must have, work can be done on this before #61 if it so happens.

@Almenon
Copy link
Owner Author

Almenon commented Jan 11, 2020

I implemented this... problem is it's rather slow :(

The python time is fine, it only adds ~40ms. The problem is that there is a larger amount of data being transmitted. The same problem happens even if you use the native print (with native print hardcoded to print what metadata print would print). Maybe I should solve #2 before I release this

@Almenon
Copy link
Owner Author

Almenon commented Jul 3, 2020

I need to revisit this now that I refactored how print results are outputted it might be faster

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

No branches or pull requests

1 participant