inspection

Decorator changing function status from method to function

本秂侑毒 提交于 2019-12-06 02:13:59
问题 [Updated]: Answer inline below question I have an inspecting program and one objective is for logic in a decorator to know whether the function it is decorating is a class method or regular function. This is failing in a strange way. Below is code run in Python 2.6: def decorate(f): print 'decorator thinks function is', f return f class Test(object): @decorate def test_call(self): pass if __name__ == '__main__': Test().test_call() print 'main thinks function is', Test().test_call Then on

Can't get argspec for Python callables?

ぃ、小莉子 提交于 2019-12-05 01:22:13
I'm playing with Python callable. Basically you can define a python class and implement __call__ method to make the instance of this class callable. e.g., class AwesomeFunction(object): def __call__(self, a, b): return a+b Module inspect has a function getargspec, which gives you the argument specification of a function. However, it seems I cannot use it on a callable object: fn = AwesomeFunction() import inspect inspect.getargspec(fn) Unfortunately, I got a TypeError: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.6/inspect.py", line 803, in

Decorator changing function status from method to function

Deadly 提交于 2019-12-04 07:14:27
[Updated]: Answer inline below question I have an inspecting program and one objective is for logic in a decorator to know whether the function it is decorating is a class method or regular function. This is failing in a strange way. Below is code run in Python 2.6: def decorate(f): print 'decorator thinks function is', f return f class Test(object): @decorate def test_call(self): pass if __name__ == '__main__': Test().test_call() print 'main thinks function is', Test().test_call Then on execution: decorator thinks function is <function test_call at 0x10041cd70> main thinks function is <bound

How do I get the value and type of the current exception in C++ using gdb?

。_饼干妹妹 提交于 2019-12-03 09:28:31
gdb allows one to catch exceptions when they're thrown, and when they're caught. But sometimes the line an exception is thrown has no symbols, or a breakpoint is triggered during exception handling. How do I inspect the value of the current exception? Updated Here's some info from the GDB Manual There are currently some limitations to C++ exception handling (catch throw and catch catch) in gdb: If you call a function interactively, gdb normally returns control to you when the function has finished executing. If the call raises an exception, however, the call may bypass the mechanism that

findViewById() may produce NullPointerException

孤街醉人 提交于 2019-12-01 04:14:12
I have many of these calls: (ListView) getView().findViewById(R.id.main_list_view); (TextView) getView().findViewById(R.id.items_no); .... and AndroidStudio tells me that they may procude a NullPointerException : Method invocation getView().findViewById(R.id.main_list_view) may produce java.lang.NullPointerException less... (Ctrl+F1) This inspection analyzes method control and data flow to report possible conditions that are always true or false, expressions whose value is statically proven to be constant, and situations that can lead to nullability contract violations. Variables, method

hide Intellij Idea yellow light bulb

不问归期 提交于 2019-11-30 05:47:58
Is there a way to hide yellow light bulb, which greatly annoys me showing on every line. I don't want to disable any inspections. I just want to hide yellow light bulb. I'm trying to switch from eclipse (not the first time) and this is one of the thing that annoys me greatly and prevent from switching. I know that I can make refactoring using alt+enter, why remind me constantly about it? There is an option, but it's not exposed in the preferences dialog. Add or modify the following line inside the <component name="EditorSettings"> section in your editor.xml file and restart IntelliJ IDEA:

Ruby equivalent of Python's “dir”?

前提是你 提交于 2019-11-29 21:14:57
In Python we can "dir" a module, like this: >>> import re >>> dir(re) And it lists all functions in the module. Is there a similar way to do this in Ruby? As far as I know not exactly but you get somewhere with object.methods.sort I like to have this in my .irbrc: class Object def local_methods (methods - Object.instance_methods).sort end end So when I'm in irb: >> Time.now.local_methods => ["+", "-", "<", "<=", "<=>", ">", ">=", "_dump", "asctime", "between?", "ctime", "day", "dst?", "getgm", "getlocal", "getutc", "gmt?", "gmt_offset", "gmtime", "gmtoff", "hour", "isdst", "localtime", "mday",

hide Intellij Idea yellow light bulb

自古美人都是妖i 提交于 2019-11-29 05:00:41
问题 Is there a way to hide yellow light bulb, which greatly annoys me showing on every line. I don't want to disable any inspections. I just want to hide yellow light bulb. I'm trying to switch from eclipse (not the first time) and this is one of the thing that annoys me greatly and prevent from switching. I know that I can make refactoring using alt+enter, why remind me constantly about it? 回答1: There is an option, but it's not exposed in the preferences dialog. Add or modify the following line

What does “Can be package local” mean? (IDEA Inspection)

怎甘沉沦 提交于 2019-11-28 21:01:25
I used IntelliJ for "Inspect Code", and one of its results is: Problem synopsis Can be package local (at line 18 (public class HeartBeat) ) What does it mean, how can I fix it? it whole class is like this: package com.xxxxxxxxxxx.app.xxxx; public class HeartBeat { private static final Logger LOG = LoggerFactory.getLogger( HeartBeat.class ); private final File heartBeatFile; public HeartBeat( File heartBeatFile ) { this.heartBeatFile = heartBeatFile; } public void beat() { try { FileUtils.writeStringToFile( heartBeatFile, String.valueOf( System.currentTimeMillis() ) ); } catch( IOException e )

Ruby equivalent of Python's “dir”?

自古美人都是妖i 提交于 2019-11-28 17:22:19
问题 In Python we can "dir" a module, like this: >>> import re >>> dir(re) And it lists all functions in the module. Is there a similar way to do this in Ruby? 回答1: As far as I know not exactly but you get somewhere with object.methods.sort 回答2: I like to have this in my .irbrc: class Object def local_methods (methods - Object.instance_methods).sort end end So when I'm in irb: >> Time.now.local_methods => ["+", "-", "<", "<=", "<=>", ">", ">=", "_dump", "asctime", "between?", "ctime", "day", "dst?