Questions tagged [inspect]

DO NOT USE! THIS IS AMBIGUOUS. You might be looking for [web-inspector].

610 questions
3
votes
3 answers

about_classes.rb inspect and self in ruby

I'm currently working on about_classes.rb. I'm confused on the concept of inspect and how it relates to self. Does calling an object automatically return the inspect method for that object? class Dog7 attr_reader :name def…
Uronacid
  • 41
  • 3
3
votes
1 answer

How to get firstlineno for wraped function with __code__ in python?

I want to get the co_firstlineno for function in static way, The unwrapped function is ok, But if a method is wrapped, I can only get the lineno where the wrapper function is located. md.py import functools def run(func): …
Alex
  • 150
  • 9
3
votes
2 answers

Inspect import path string from object

If an object is a module's class or function I need to retrieve the absolute import path as a string. Example: >>> from a.b.c import foo >>> get_import_path(foo) 'a.b.c.foo' I tried to look into inspect module but there's nothing to do that.
Giampaolo Rodolà
  • 12,488
  • 6
  • 68
  • 60
3
votes
3 answers

python get parameters of passed function

I want to pass a function, f(a=1,b=2) into g and use the 'a' value in g def f(a,b): pass def g(f): #print f.a g(f(1,2)) should result in an output of 1 I looked into the inspect module but can't seem to get hold of f in g This is as far as my…
3
votes
0 answers

How to get the source code for property in python

I want to programmatically get the source code for a given class property (e.g., pandas.DataFrame.iloc). I tried using inspect.findsource(), which works fine for classes and functions. However, it doesn't work for properties. import pandas import…
Ida
  • 2,919
  • 3
  • 32
  • 40
3
votes
0 answers

Reference cycles when using inspect module

The documentation says: Note Keeping references to frame objects, as found in the first element of the frame records these functions return, can cause your program to create reference cycles. Once a reference cycle has been created, the lifespan of…
x-yuri
  • 16,722
  • 15
  • 114
  • 161
3
votes
0 answers

How to get parameters list of a function covered by a decorator?

I get function parameters list in this way: def foo(a, b, c): # do something return print inspect.getargspec(foo) Output is: ArgSpec(args=['a', 'b', 'c'], varargs=None, keywords=None, defaults=None) But if the target function has a…
Rocky.L
  • 59
  • 4
3
votes
1 answer

finding from import statements in python

Let's say I have a module with some code in it and I want to find the imported libraries for this module. import os import pandas as pd import numpy as np from os.path import basename, join def export(df, folder): """some export thing (not…
code base 5000
  • 3,812
  • 13
  • 44
  • 73
3
votes
1 answer

Matching default values to parameter name

How do I match my functions variable names to the default values using python and inspect? def foo(x:int,y:int=5) -> int: return a+b inspect.getfullargspec(foo) FullArgSpec(args=['x', 'y'], varargs=None, varkw=None, defaults=(4,), kwonlyargs=[],…
code base 5000
  • 3,812
  • 13
  • 44
  • 73
3
votes
1 answer

Python function introspection: what members of a class passed as argument are mentioned inside it?

Say that I have a function like the following: def eggs(a,b,c): if c.foo: return a + b.bar else: return c.spam I'd like to have a higher order function capable of introspecting the function passed and retrieve what members…
3
votes
1 answer

Why can not we inspect the source code of the `__builtins__` module?

Why can not I inspect the source code of the __builtins__ module? >>> import inspect >>> inspect.getsource(__builtins__) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/inspect.py", line 701, in…
Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
3
votes
1 answer

where does the annotation for a member variable live

if i do something like this: def f(x: str): pass i can easily see this type hint for x if i do: print(f.__annotations__) however, i can't seem to figure out where the annotations live if i do something like this: class C: def…
acushner
  • 9,595
  • 1
  • 34
  • 34
3
votes
1 answer

How do I get the value of an argument passed to a decorator in Python?

Given the code below, I am trying to identify the arguments sent to decorators that are used by a class. Specifically, I am trying to identify the value 100 that is passed into the make_hyper decorator that is used in the Dog class. Optimally, I…
retsigam
  • 540
  • 1
  • 5
  • 13
3
votes
4 answers

Node.js Server crashed when Refresh Browser

I tried to build a chat box server by node.js. When the browser requestes the page, it workes well at first. But when I refresh the page, the Server crashes. Below is the error message: events.js:183 throw er; // Unhandled 'error' event …
周雪静
  • 153
  • 1
  • 3
  • 10
3
votes
5 answers

In Javascript, is their a way to inspect an objects methods and attributes such as Python's dir()?

In Javascript is their a way to inspect an objects methods and attributes such as Python's dir() ? dir(object) returns object.height object.width object.compute_days_till_birthday() etc.....
b_dev
  • 2,568
  • 6
  • 34
  • 43