PyDev: How to avoid "assignment to reserved built-in symbol: id"? - eclipse

I have PyDev 5.6 (for Eclipse). I'm getting "assignment to reserved built-in symbol: id" warning for the id:
class bla(object):
def myfn(self, task):
id = task['id']
I found #1457 Bogus "Assignment to reserved built-in symbol" warnings
(https://sourceforge.net/p/pydev/bugs/1457/)
but it's for PyDev 2.3 and issue should be fixed in 2.6.0
I don't want to disable all "Redefinition of builtin symbols" in Code Analysis (it's possible in Preferences). Someone suggested to use Id or _id instead of id , but for me the id is variable and I want to keep it in lower case.
Is it possible to set Eclipse/PyDev to ignore this symbol?
Currently it's in class and it's used locally inside func "myfn" (or other).
But I would like to ignore it also on "main" level. If you work w/ databases, 'id' is everywhere :)
I'm new in Eclipse and PyDev. Maybe I overlooked some setting.
Thanks.

What #S.Ahmad said, is correct, you can ignore it with comments in the code (and use PyDev itself to help you there).
Another option would be disabling that check altogether (for all variables) in PyDev > Editor > Code Analysis > Others > Redefinition of builtin symbols (there's no option to disable it just for id).
Personally, I try to stay clear from redefining builtins such as you're doing (even id) and give it a more meaningful name when assigning to a local (i.e.: in your example I'd call it task_id, not only id), and it's usually straightforward to define it, as the id is usually related to id of something (IMHO, it also makes code clearer to follow later on if you give the id more meaning).

Select/Highlight the variable and then press Ctrl+1.
Choose #ReservedAssignment from the dropdown menu. This will suppress the warning.
Or you can simply paste # #ReservedAssignment after each variable to suppress the message.
I don't think we can suppress such messages for a variable globally but I could be wrong.

Now I found out that id(var) is func returning address of variable/object. Hmmm... maybe that's reason for this warning.
I did little research:
>>> a= 2
>>> a
2
>>> type(a)
<class 'int'>
>>> id(a)
1650106848
>>> a.__str__
<method-wrapper '__str__' of int object at 0x00000000625AA1E0>
>>> "{:02x}".format( id(a) ) ### hex( id(a) )
'625aa1e0' ### so it's address
>>> type( id )
<class 'builtin_function_or_method'>
>>> id = 1
>>> type( id )
<class 'int'>
>>> "{:02x}".format( id(a) ) ### id() doesn't work now
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
>>>
How dangerous can be to do id = something and destroy id() functionality?

Related

Inspect unprocessed collection objects in Eclipse

Eclipse has a feature that represents some types of Java collections (most notably ArrayList and ArrayDeque) in a simplified way in the inspect tool (also in the Variables and Expression views):
d = ArrayDeque<E> (id=33)
[0] = "somevalue" (id=57)
[1] = "someothervalue (id=59)
In most other classes, instead of the [0] and [1] entries, the inspect tool will show fields of the object, including their names. I'm interested in looking at the internals of a live ArrayDeque.
Is there a way to make the inspect tool show the real fields of the ArrayDeque, so that the output looks more like this?:
"d" = ArrayDeque<E> (id=33)
elements = Object[] (id=34)
head = 2
tail = 4
I'm using Eclipse 2018-12 (4.10.0).
EDIT: I have already tried using a subclass of ArrayDeque, but it doesn't help.
I have found a way:
In Preferences > Java > Debug > Logical Structures, there is a definiton that performs toArray() on any java.util.Collection before the inspect tool shows the result.
While it is not possible to remove that default entry, you can add an entry for a more specific type:
Qualified type name: java.util.ArrayDeque
Description: Shows ArrayDeque internals
Code: this

How to convert Blender blend (or obj) file to .h file?

I would like to convert a 3d model (.obj like blender) to .h file. there is a tool at github but when I run it, I got a message error :
tool:
https://github.com/HBehrens/obj2opengl/
my commend line:
C:\Users\***>perl C:\Users\***\Desktop\vuforia\obj2opengl.pl C:\
Users\***\Desktop\vuforia\cc.obj
cc.obj is an export of blender software .
error :
Can't use 'defined(#array)' (Maybe you should just omit the defined()?) at C:\Users\***\Desktop\vuforia\obj2opengl.pl line 118.
line 118 :
if(defined(#center)) { //line 118
$xcen = $center[0];
$ycen = $center[1];
$zcen = $center[2];
}
I don't know where is the problem.
my OS is windows 64 . I installed perl before .
Can't use 'defined(#array)' (Maybe you should just omit the defined()?)
This tells you that the syntax defined(#array) is not valid, and even gives a hint. All you need to do is remove the defined(). Your code would then read
if(#center) {
$xcen = $center[0];
$ycen = $center[1];
$zcen = $center[2];
}
The if evaluation forces the array into scalar context, which makes it return its number of elements. That's probably 3, or 0. If it's 0 then it's a false value and the block is skipped. 3 on the other hand is a true value and the block will be executed.
The defined(#array) syntax was deprecated from Perl.
Use of defined on aggregates (hashes and arrays) is deprecated. It used to report whether memory for that aggregate had ever been allocated. This behavior may disappear in future versions of Perl.
The version of Perl you installed is newer than the version the author of your script used, and this is a rare occasion of an incompatible change.

Find category of MATLAB mlint warning ID

I'm using the checkcode function in MATLAB to give me a struct of all error messages in a supplied filename along with their McCabe complexity and ID associated with that error. i.e;
info = checkcode(fileName, '-cyc','-id');
In MATLAB's preferences, there is a list of all possible errors, and they are broken down into categories. Such as "Aesthetics and Readability", "Syntax Errors", "Discouraged Function Usage" etc.
Is there a way to access these categories using the error ID gained from the above line of code?
I tossed around different ideas in my head for this question and was finally able to come up with a mostly elegant solution for how to handle this.
The Solution
The critical component of this solution is the undocumented -allmsg flag of checkcode (or mlint). If you supply this argument, then a full list of mlint IDs, severity codes, and descriptions are printed. More importantly, the categories are also printed in this list and all mlint IDs are listed underneath their respective mlint category.
The Execution
Now we can't simply call checkcode (or mlint) with only the -allmsg flag because that would be too easy. Instead, it requires an actual file to try to parse and check for errors. You can pass any valid m-file, but I have opted to pass the built-in sum.m because the actual file itself only contains help information (as it's real implementation is likely C++) and mlint is therefore able to parse it very rapidly with no warnings.
checkcode('sum.m', '-allmsg');
An excerpt of the output printed to the command window is:
INTER ========== Internal Message Fragments ==========
MSHHH 7 this is used for %#ok and should never be seen!
BAIL 7 done with run due to error
INTRN ========== Serious Internal Errors and Assertions ==========
NOLHS 3 Left side of an assignment is empty.
TMMSG 3 More than 50,000 Code Analyzer messages were generated, leading to some being deleted.
MXASET 4 Expression is too complex for code analysis to complete.
LIN2L 3 A source file line is too long for Code Analyzer.
QUIT 4 Earlier syntax errors confused Code Analyzer (or a possible Code Analyzer bug).
FILER ========== File Errors ==========
NOSPC 4 File <FILE> is too large or complex to analyze.
MBIG 4 File <FILE> is too big for Code Analyzer to handle.
NOFIL 4 File <FILE> cannot be opened for reading.
MDOTM 4 Filename <FILE> must be a valid MATLAB code file.
BDFIL 4 Filename <FILE> is not formed from a valid MATLAB identifier.
RDERR 4 Unable to read file <FILE>.
MCDIR 2 Class name <name> and #directory name do not agree: <FILE>.
MCFIL 2 Class name <name> and file name do not agree: <file>.
CFERR 1 Cannot open or read the Code Analyzer settings from file <FILE>. Using default settings instead.
...
MCLL 1 MCC does not allow C++ files to be read directly using LOADLIBRARY.
MCWBF 1 MCC requires that the first argument of WEBFIGURE not come from FIGURE(n).
MCWFL 1 MCC requires that the first argument of WEBFIGURE not come from FIGURE(n) (line <line #>).
NITS ========== Aesthetics and Readability ==========
DSPS 1 DISP(SPRINTF(...)) can usually be replaced by FPRINTF(...).
SEPEX 0 For better readability, use newline, semicolon, or comma before this statement.
NBRAK 0 Use of brackets [] is unnecessary. Use parentheses to group, if needed.
...
The first column is clearly the mlint ID, the second column is actually a severity number (0 = mostly harmless, 1 = warning, 2 = error, 4-7 = more serious internal issues), and the third column is the message that is displayed.
As you can see, all categories also have an identifier but no severity, and their message format is ===== Category Name =====.
So now we can just parse this information and create some data structure that allows us to easily look up the severity and category for a given mlint ID.
Again, though, it can't always be so easy. Unfortunately, checkcode (or mlint) simply prints this information out to the command window and doesn't assign it to any of our output variables. Because of this, it is necessary to use evalc (shudder) to capture the output and store it as a string. We can then easily parse this string to get the category and severity associated with each mlint ID.
An Example Parser
I have put all of the pieces I discussed previously together into a little function which will generate a struct where all of the fields are the mlint IDs. Within each field you will receive the following information:
warnings = mlintCatalog();
warnings.DWVRD
id: 'DWVRD'
severity: 2
message: 'WAVREAD has been removed. Use AUDIOREAD instead.'
category: 'Discouraged Function Usage'
category_id: 17
And here's the little function if you're interested.
function [warnings, categories] = mlintCatalog()
% Get a list of all categories, mlint IDs, and severity rankings
output = evalc('checkcode sum.m -allmsg');
% Break each line into it's components
lines = regexp(output, '\n', 'split').';
pattern = '^\s*(?<id>[^\s]*)\s*(?<severity>\d*)\s*(?<message>.*?\s*$)';
warnings = regexp(lines, pattern, 'names');
warnings = cat(1, warnings{:});
% Determine which ones are category names
isCategory = cellfun(#isempty, {warnings.severity});
categories = warnings(isCategory);
% Fix up the category names
pattern = '(^\s*=*\s*|\s*=*\s*$)';
messages = {categories.message};
categoryNames = cellfun(#(x)regexprep(x, pattern, ''), messages, 'uni', 0);
[categories.message] = categoryNames{:};
% Now pair each mlint ID with it's category
comp = bsxfun(#gt, 1:numel(warnings), find(isCategory).');
[category_id, ~] = find(diff(comp, [], 1) == -1);
category_id(end+1:numel(warnings)) = numel(categories);
% Assign a category field to each mlint ID
[warnings.category] = categoryNames{category_id};
category_id = num2cell(category_id);
[warnings.category_id] = category_id{:};
% Remove the categories from the warnings list
warnings = warnings(~isCategory);
% Convert warning severity to a number
severity = num2cell(str2double({warnings.severity}));
[warnings.severity] = severity{:};
% Save just the categories
categories = rmfield(categories, 'severity');
% Convert array of structs to a struct where the MLINT ID is the field
warnings = orderfields(cell2struct(num2cell(warnings), {warnings.id}));
end
Summary
This is a completely undocumented but fairly robust way of getting the category and severity associated with a given mlint ID. This functionality existed in 2010 and maybe even before that, so it should work with any version of MATLAB that you have to deal with. This approach is also a lot more flexible than simply noting what categories a given mlint ID is in because the category (and severity) will change from release to release as new functions are added and old functions are deprecated.
Thanks for asking this challenging question, and I hope that this answer provides a little help and insight!
Just to close this issue off. I've managed to extract the data from a few different places and piece it together. I now have an excel spreadsheet of all matlab's warnings and errors with columns for their corresponding ID codes, category, and severity (ie, if it is a warning or error). I can now read this file in, look up ID codes I get from using the 'checkcode' function and draw out any information required. This can now be used to create analysis tools to look at the quality of written scripts/classes etc.
If anyone would like a copy of this file then drop me a message and I'll be happy to provide it.
Darren.

issue with rpyc marshalling of objects

I am using rpyc (v 3.3.0) to get the list of processes running on a remote server using psutil module. My code is as below.
server='hkl20056309'
rpcClient = rpyc.classic.connect(server)
rpsutil = rpcClient.modules.psutil
procs = rpsutil.get_process_list()
I am getting the list of procs correctly but some of the processes attributes are not set correctly. for example:
>>> procs[166]._name
'mingetty'
>>> procs[140]._name
>>> procs[141]._name
>>> procs[142]._name
>>> procs[142]
<psutil.Process(pid=1828, name='gatengine') at 17483536>
>>> procs[142]._name
'gatengine'
>>>
If you see procs[142]._name is not printed (value is None) until I access the object. If I print all the processes, I see the name as None for 143rd process object in the list. But after I access the object, suddenly I can see the correct value for the name.
Any suggestions on how I can resolve this issue?
Never seen such an issue with RPyC. It's probably something to do with that Process. If you call str(proc) and then proc._name, instead of printing, does it help? Also, it seems like you're trying to use a private member (_name)... Perhaps that's the issue? Isn't there some public property you can use?

Problem with the deprecation of the postgresql XML2 module 'xml_is_well_formed' function

We need to make extensive use of the 'xml_is_well_formed' function provided by the XML2 module.
Yet the documentation says that the xml2 module will be deprecated since "XML syntax checking and XPath queries"
is covered by the XML-related functionality based on the SQL/XML standard in the core server from PostgreSQL 8.3 onwards.
However, the core function XMLPARSE does not provide equivalent functionality since when it detects an invalid XML document,
it throws an error rather than returning a truth value (which is what we need and currently have with the 'xml_is_well_formed' function).
For example:
select xml_is_well_formed('<br></br2>');
xml_is_well_formed
--------------------
f
(1 row)
select XMLPARSE( DOCUMENT '<br></br2>' );
ERROR: invalid XML document
DETAIL: Entity: line 1: parser error : expected '>'
<br></br2>
^
Entity: line 1: parser error : Extra content at the end of the document
<br></br2>
^
Is there some way to use the new, core XML functionality to simply return a truth value
in the way that we need?.
Thanks,
-- Mike Berrow
After asking about this on the pgsql-hackers e-mail list, I am happy to report that the guys there agreed that it was still needed and they have now moved this function to the core.
See:
http://web.archiveorange.com/archive/v/alpsnGpFlZa76Oz8DjLs
and
http://postgresql.1045698.n5.nabble.com/review-xml-is-well-formed-td2258322.html