Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
16 views

I'm trying specify annotations with inspect module: import inspect from inspect import Parameter from fastapi import FastAPI, Query from fastapi.params import Depends from pydantic import BaseModel ...
Альберт Александров's user avatar
3 votes
4 answers
374 views

The following code throws a ValueError ('invalid method signature') import inspect class Foo: boo = lambda: 'baa' print(inspect.signature(Foo().boo)) Why? Changing it to boo = lambda x: 'baa'...
pqzpkaot's user avatar
  • 431
0 votes
1 answer
119 views

tldr; inspect.signature gives us a function's signature, but this signature can lie (as assigning to the __signature__ attribute of a function will reveal. Is there a python function (builtin if ...
thorwhalen's user avatar
  • 2,442
1 vote
2 answers
115 views

I need to get the source of a function 'get_id' and inspect.getsource() is returning the source of the function 'update_creds' and I have no idea why Some specifics about the environment: Its running ...
user23530071's user avatar
0 votes
1 answer
467 views

following the basic pytorch tutorial, I'm trying to experiment with different CNN architectures (different number of layers, channels per layer, etc.) and I want to be organized so I'm trying to use ...
Ariel Yael's user avatar
0 votes
0 answers
240 views

I need to get the class (not just the name, the real class ref) from an inspect stack return. Say i have this: def methodthatneedcls(): cls = ### code here class excls: def somemethod(): ...
NoBlockhit's user avatar
1 vote
1 answer
132 views

Consider this code: from sqlalchemy import exists import inspect print(inspect.getfile(exists)) # Effectively calls: print(exists.__code__.co_filename) On 2 systems I've tested it on it prints: <...
sashkent3's user avatar
0 votes
0 answers
147 views

getmembers from inspect doesn't return all the members. I am using this on a locally installed package, example code: from inspect import getmembers, ismodule import xyz getmembers(xyz, ismodule) # []...
Ani Menon's user avatar
  • 28.4k
3 votes
0 answers
289 views

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 ...
Ida's user avatar
  • 2,999
14 votes
3 answers
2k views

Let's say, I have a bunch of functions a, b, c, d and e and I want to find out if they directly use a loop: def a(): for i in range(3): print(i**2) def b(): i = 0 while i < 3: ...
finefoot's user avatar
  • 11.6k
15 votes
2 answers
13k views

I'd like to print every line of python script as it's being executed, as well as the log from the console as every line is being executed. For example, for this script: import time print 'hello' ...
Chris's user avatar
  • 5,904
5 votes
0 answers
533 views

I'm having trouble understanding the differences between stack frames and execution frames, mostly with respect to the traceback and inspect modules (in Python 3). I thought they were the same but ...
Michael B's user avatar
  • 289
4 votes
1 answer
2k views

I have a multimodule Python package which has one file with class MyClass and few files with functions (one file can contain more than 1 function). I tried to get all functions in this package. ...
VeLKerr's user avatar
  • 3,207
40 votes
7 answers
51k views

I want to log all the names of functions where my code is going. It does not matter who is calling the function. import inspect def whoami(): return inspect.stack()[1][3] def foo(): print(...
John Kaff's user avatar
  • 2,095
54 votes
2 answers
15k views

What is the difference between: >>> import inspect >>> print(inspect.getouterframes(inspect.currentframe())) [(<frame object at 0x8fc262c>, '<stdin>', 1, '<module>',...
jmunsch's user avatar
  • 24.3k
11 votes
0 answers
3k views

I'm trying to get Python to list all modules in a namespace package. I have the following file structure: cwd |--a | `--ns | |--__init__.py | `--amod.py |--b | `--ns | |--__init__.py | ...
siebz0r's user avatar
  • 20.6k
102 votes
12 answers
216k views

I am trying to use functional programming to create a dictionary containing a key and a function to execute: myDict={} myItems=("P1","P2","P3",...."Pn") def myMain(key): def ExecP1(): ...
JohnnyDH's user avatar
  • 2,075
101 votes
7 answers
52k views

How to get all methods of a given class A that are decorated with the @decorator2? class A(): def method_a(self): pass @decorator1 def method_b(self, b): pass @decorator2 ...
kraiz's user avatar
  • 2,218
13 votes
3 answers
3k views

Given a function: def func(f1, kw='default'): pass bare_argspec = inspect.getargspec(func) @decorator def func2(f1, kw='default'): pass decorated_argspec = inspect.getargspec(func2) How can ...
Chris R's user avatar
  • 18k
17 votes
5 answers
8k views

I'm trying to get the name of all methods in my class. When testing how the inspect module works, i extraced one of my methods by obj = MyClass.__dict__['mymethodname']. But now inspect.ismethod(obj)...
Eskil's user avatar
  • 3,595
430 votes
13 answers
343k views

I've seen plenty of examples of people extracting all of the classes from a module, usually something like: # foo.py class Foo: pass # test.py import inspect import foo for name, obj in inspect....
mcccclean's user avatar
  • 7,981