Questions tagged [python-inspect]

10 questions
1
vote
0 answers

Unable to inspecting class name for caller class methods with @staticmethod decorator

Trying to use How to get the caller class name inside a function of another class in python? I ran into a peculiar issue with decorated methods. stack[1].frame.f_locals["self"].__class__.__name__ works in case of instance method call but when…
Ulysses
  • 5,616
  • 7
  • 48
  • 84
0
votes
0 answers

Is it possible to get a properties fully qualified when only property is passed into function?

I am trying to get fully qualified name from a property. Example class class Foo: def __init__(self, val: int): self._val = val @property def myval(self) -> int: return self._val I am attempting to get full qualified…
Amour Spirit
  • 125
  • 7
0
votes
0 answers

Can I use an inspect.Signature instance as a signature for function that an ide will see?

Can I use an inspect.Signature instance as a signature for function that an ide will see? I am asking because I want a way to requires specikic key value pairs, and a catch all type for unknown other keywords. Function signatures and kwargs let one…
0
votes
1 answer

Using weights and biases for storing pytorch experiments of different architectures

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 wandb. I'm looking for a simple way to try out…
Ariel Yael
  • 361
  • 2
  • 10
0
votes
0 answers

Programmatically collect APIs from a library in Python

I am trying to get all APIs from libraries (e.g. Scikit-Learn, Pandas) programmatically. I use importlib and inspect modules to do this. import inspect import importlib def get_modules(lib_name): module_dict = {} for name, val in…
akalanka
  • 553
  • 7
  • 21
0
votes
1 answer

Using inspect.getsourcelines() for a module that is not stored in the same folder

I have a module stored in some specific local location on which I am performing dynamic import using, importlib in python. After importing the module I am using file.readlines() to read all the lines in the file. If the file has a function called…
0
votes
0 answers

Inspect find class in stack

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(): methodthatneedcls() …
NoBlockhit
  • 369
  • 2
  • 15
0
votes
1 answer

python's inspect.getfile returns ""

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: What does it mean? Could anything…
sashkent3
  • 15
  • 4
0
votes
0 answers

Edit parameters and typehints for a class method

I have a class: class Foo: def __init__(self, *args, *kwargs): pass As you see, this code will display args & kwargs for typehints. But, I want to inspect method and change it's arguments and typehints using inspect.Signature, and I…
user13699857
0
votes
0 answers

inspect.getmembers doesn't return member until a run a help()

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) # [] help('xyz.abc') getmembers(xyz, ismodule) #…
Ani Menon
  • 27,209
  • 16
  • 105
  • 126