Giter Site home page Giter Site logo

SOURCE IS UNAVAILABLE about pysnooper HOT 8 OPEN

lixuanhng avatar lixuanhng commented on May 28, 2024
SOURCE IS UNAVAILABLE

from pysnooper.

Comments (8)

cool-RR avatar cool-RR commented on May 28, 2024 1

I guess so. It's possible it could be implemented, but you'll need to roll up your sleeves for that.

from pysnooper.

cool-RR avatar cool-RR commented on May 28, 2024

I'm guessing you didn't put the code in the file, but rather in some shell. I'm guessing that shell isn't IPython. Which shell is it?

from pysnooper.

guyb2022 avatar guyb2022 commented on May 28, 2024

I run the script on win10 python 3.11.0
It works correctlly
Output:
Starting var:.. number = 6
11:50:32.973112 call 4 def number_to_bits(number):
11:50:32.975097 line 5 if number:
11:50:32.976097 line 6 bits = []
New var:....... bits = []
11:50:32.976097 line 7 while number:
11:50:32.976097 line 8 number, remainder = divmod(number, 2)
Modified var:.. number = 3
New var:....... remainder = 0
11:50:32.977117 line 9 bits.insert(0, remainder)
Modified var:.. bits = [0]
11:50:32.977117 line 10 return bits
11:50:32.978115 return 10 return bits
Return value:.. [0]
Elapsed time: 00:00:00.005987

from pysnooper.

Sionwage avatar Sionwage commented on May 28, 2024

I get the same output when using Jupyterlab.

from functools import reduce
import pysnooper

@pysnooper.snoop()
def multi(x,y):
    return x*y

print(reduce(multi,range(1,4)))
multi(5,2)

Output

Source path:... C:\Users\...\AppData\Local\Temp\ipykernel_17756\20432242.py
Starting var:.. x = 1
Starting var:.. y = 2
17:51:19.570314 call         4 SOURCE IS UNAVAILABLE
17:51:19.570314 line         6 SOURCE IS UNAVAILABLE
17:51:19.570314 return       6 SOURCE IS UNAVAILABLE
Return value:.. 2
Elapsed time: 00:00:00.000000
Starting var:.. x = 2
Starting var:.. y = 3
17:51:19.570314 call         4 SOURCE IS UNAVAILABLE
17:51:19.570314 line         6 SOURCE IS UNAVAILABLE
17:51:19.570314 return       6 SOURCE IS UNAVAILABLE
Return value:.. 6
Elapsed time: 00:00:00.000000
Starting var:.. x = 5
Starting var:.. y = 2
17:51:19.570314 call         4 SOURCE IS UNAVAILABLE
17:51:19.570314 line         6 SOURCE IS UNAVAILABLE
17:51:19.570314 return       6 SOURCE IS UNAVAILABLE
Return value:.. 10
Elapsed time: 00:00:00.000000

from pysnooper.

Sionwage avatar Sionwage commented on May 28, 2024

Calling just regular python repl from the command prompt:

Python 3.11.4 (tags/v3.11.4:d2340ef, Jun  7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pysnooper
>>> def multi(x,y):
...     return x*y
...
>>> with pysnooper.snoop()
  File "<stdin>", line 1
    with pysnooper.snoop()
                          ^
SyntaxError: expected ':'
>>> with pysnooper.snoop():
...     multi(5,2)
...
Source path:... <stdin>
New var:....... __name__ = '__main__'
New var:....... __doc__ = None
New var:....... __package__ = None
New var:....... __loader__ = <class '_frozen_importlib.BuiltinImporter'>
New var:....... __spec__ = None
New var:....... __annotations__ = {}
New var:....... __builtins__ = <module 'builtins' (built-in)>
New var:....... pysnooper = <module 'pysnooper' from 'C:\\Users\\....\\Ap....11\\Lib\\site-packages\\pysnooper\\__init__.py'>
New var:....... multi = <function multi at 0x000002049302E980>
18:03:12.070700 line         2 SOURCE IS UNAVAILABLE
10
18:03:12.071645 line         1 SOURCE IS UNAVAILABLE
Elapsed time: 00:00:00.000945
>>>

from pysnooper.

cool-RR avatar cool-RR commented on May 28, 2024

@Sionwage Thanks for reporting. It would be good to be able to get the source in these cases, but I probably won't work on this because it's not important enough for me. If you're interested feel free to dig in and implement it.

from pysnooper.

Sionwage avatar Sionwage commented on May 28, 2024

Ok, I think I found why I get the source is unavailable for me.

I was running this with Jupyterlab in a cell. If I move the function to a '.py' file like 'test.py' with this code:

import pysnooper

@pysnooper.snoop()
def adder(x, y):
    answer = x + y
    return answer

if __name__ == '__main__':
    print(adder(5, 20))

and call the function from Jupyterlab by running this:

import test

test.adder(5, 20)

I get this output that matches the functionality outlined in the readme:

Source path:... C:\Users\...\OneDrive - ...\Documents\Python\temp\test.py
Starting var:.. x = 5
Starting var:.. y = 20
11:24:16.302453 call         4 def adder(x, y):
11:24:16.302453 line         5     answer = x + y
New var:....... answer = 25
11:24:16.302453 line         6     return answer
11:24:16.302453 return       6     return answer
Return value:.. 25
Elapsed time: 00:00:00.000000

25

I think that this cannot be used with its full functionality in Jupyterlab or Ipython unless there is an actual source file for PySnooper to scrape from?

from pysnooper.

Sionwage avatar Sionwage commented on May 28, 2024

I'm just tickled I got this working as it is very handy. This is probably my cue to get out of Jupyter and start using a more mature workflow.

from pysnooper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.