Questions tagged [introspection]

A capability of some object-oriented programming languages to determine the type of an object at runtime.

Some OOP languages providing Type Introspection ability : Ruby, Objective-C, C++, Java, PHP, Perl, Python, Object Pascal, Actionscript (as3)

The introspection is done differently, depending on the form of program, it is performed upon: inspecting a source code or compiled byte-code is called compile-time introspection, while inspecting properties of running code is a run-time introspection.

For example, Java supports both types of introspection: users of run-time introspection typically perform it via , while compile-time introspection can be implemented with tools or .

http://en.wikipedia.org/wiki/Type_introspection

1021 questions
23
votes
2 answers

Thread name longer than 15 chars?

By using functions like prctl, or pthread_set_name_np it's possible to change the name of a thread. The limit both functions imposes, at least in Linux 2.6.38, is that the name cannot be longer than 15 characters (NULL termination being the 16th…
dsvensson
  • 1,401
  • 12
  • 20
23
votes
3 answers

How do I inspect the methods of a Ruby object?

I am wondering if there is a Ruby method call that shows only the methods defined by the Ruby object it's called from, as opposed to all the methods defined by its ancestor classes, which is what methods seems to do.
picardo
  • 24,530
  • 33
  • 104
  • 151
23
votes
7 answers

Convert object's properties and values to array of key value pairs

I'm fairly new to JavaScript and am not sure this is possible to do but basically I would like to take an object and convert it into an array of strings in the format; array[0] = 'prop1=value1' The reasoning behind this is that I'm having a user…
evanmcdonnal
  • 46,131
  • 16
  • 104
  • 115
22
votes
2 answers

Introspecting arguments from the constructor function __init__ in Python

What is a way to extract arguments from __init__ without creating new instance. The code example: class Super: def __init__(self, name): self.name = name I am looking something like Super.__dict__.keys()type solution. Just to retrieve…
Vy.Iv
  • 829
  • 2
  • 8
  • 17
21
votes
2 answers

Python introspection: get the argument list of a method_descriptor?

A code illustration as an intro to my questions: import re, inspect, datetime inspect.getargspec (re.findall) # => # ArgSpec(args = ['pattern', 'string', 'flags'], varargs=None, # keywords=None, defaults = (0,)) type (datetime.datetime.replace) #…
abo-abo
  • 20,038
  • 3
  • 50
  • 71
21
votes
13 answers

Python introspection: access function name and docstring inside function definition

Consider the following python code: def function(): "Docstring" name = ??? doc = ??? return name, doc >>> function() "function", "Docstring" What do I need to replace the question marks with so that I get the name and the…
D R
  • 21,936
  • 38
  • 112
  • 149
20
votes
4 answers

Introspect calling object

How do I introspect A's instance from within b.func() (i.e. A's instance's self): class A(): def go(self): b=B() b.func() class B(): def func(self): # Introspect to find the calling A instance here
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
20
votes
8 answers

Java: How to find if a method is overridden from base class?

How to find out if a method is overridden by child classes? For example, public class Test { static public class B { public String m() {return "From B";}; } static public class B1 extends B { } static public class B2 extends B { public…
ZZ Coder
  • 74,484
  • 29
  • 137
  • 169
20
votes
3 answers

SQLAlchemy introspect column type with inheritance

Considering this code (and using SQLAlchemy 0.7.7): class Document(Base): __tablename__ = 'document' __table_args__ = { 'schema': 'app' } id = Column(types.Integer, primary_key=True) nom = Column(types.Unicode(256),…
tonio
  • 2,376
  • 1
  • 22
  • 28
19
votes
4 answers

What are the arguments to the types.CodeType() python call?

I'm currently trying to roll my own "marshal" code for python so i can store compiled python code on Google App Engine to serve scripts on a dynamic way. As you all can verify, "marshal" isn't supported on GAE and "pickle" can't serialize code…
19
votes
3 answers

_cmd value inside C functions

What's the value of _cmd variable when I access it from C-style function's body? Is it defined inside Objective-C methods only? P.S. This question may originate from my non-understanding of what _cmd is. I would greatly appreciate if someone…
wh1t3cat1k
  • 3,146
  • 6
  • 32
  • 38
19
votes
2 answers

How do I check if a python function changed (in live code)?

If I have a reference to a function I can check it's code object f.__code__, get a signature, then perform later checks against this signature to see if the code changed. This is good. But what if one of the funciton's dependencies changed? E.g. def…
Maxim Khesin
  • 597
  • 4
  • 10
18
votes
5 answers

Get a list of the instances in a type class in Haskell

Is there a way to programmatically get a list of instances of a type class? It strikes me that the compiler must know this information in order to type check and compile the code, so is there some way to tell the compiler: hey, you know those…
mentics
  • 6,852
  • 5
  • 39
  • 93
18
votes
1 answer

How to get struct field names in Rust?

Is there some equivalent of JS's Object.keys() for Rust's struct? I need something to generate CSV headers (I use rust-csv) from structure field names. struct Export { first_name: String, last_name: String, gender: String, …
Alexander Arutinyants
  • 1,619
  • 2
  • 23
  • 49
18
votes
7 answers

Functional programming languages introspection

I'm sketching a design of something (machine learning of functions) that will preferably want a functional programming language, and also introspection, specifically the ability to examine the program's own code in some nicely tractable format, and…
rwallace
  • 31,405
  • 40
  • 123
  • 242