Menu

#2766 Static Code Analysis fails

nextrelease
open
nobody
None
5
2026-03-25
2025-11-19
No

The Static Code Analysis of Jython scripts could catch a number of things that it doesn't, and sometimes misfires. This ticket is to collect errors.

Discussion

  • Jeremy Faden

    Jeremy Faden - 2025-11-19

    (1) undeclared global variable use could be caught.

    name='foo'
    def saveAs(evt):
           if name=='foo':
                  print 'yes'
    saveAs(0)
    

    name is undefined in the if statement because the "global name" was not declared.

     

    Last edit: Jeremy Faden 2025-11-19
  • Jeremy Faden

    Jeremy Faden - 2025-11-19

    (2) the symbol "d" in addPointDigitizer is used both for a variable and for a function name, but not in the same space. This causes the detector to misfire.

     
  • Jeremy Faden

    Jeremy Faden - 2025-11-19

    Item 2 is particularly annoying because the editor keeps jumping to show the line.

     
  • Jeremy Faden

    Jeremy Faden - 2025-12-04

    (Item 1) I've never understood why sometimes Python will realize "foo" is in the global namespace and other times it seems like it needs the global declaration. The code in item 1 runs...

     
  • Jeremy Faden

    Jeremy Faden - 2026-03-24

    (3) This incorrectly marks "ds" as not used, because the except block rewrites it.

    try:
        uri = root + '/%s/L2/MSC/$Y/$m/%s_l2_msc_bac_$Y$m$d_v$(v;sep).cdf?%s_l2_bac_fac' % (sc.upper(),sc.lower(),sc.lower() )
        print uri
        ds= getDataSet(uri,tr,monitor.getSubtaskMonitor(0,30,'Load l2_bac_fac') )
        print 'done read MSC data at %.3f' % ( ( System.currentTimeMillis()-t0 ) / 1000. )
    
    except:
    
        # The coordinate system doesn't matter.
        uri = root + '%s/L2/MSC/$Y/$m/%s_l2_msc_bac_$Y$m$d_v$(v;sep).cdf?%s_l2_bac' % (sc.upper(),sc.lower(),sc.lower() )
        print 'unable to find l2_bac_fac, loading l2_fac'
        ds= getDataSet(uri,tr,monitor.getSubtaskMonitor(0,30,'Load l2_bac') )
        print 'done read MSC data (alt) at %.3f seconds' % ( ( System.currentTimeMillis()-t0 ) / 1000. )
    
     

    Last edit: Jeremy Faden 2026-03-24
  • Jeremy Faden

    Jeremy Faden - 2026-03-24

    (4) "result" in jyds scripts should not trigger a warning.

     

    Last edit: Jeremy Faden 2026-03-24
  • Jeremy Faden

    Jeremy Faden - 2026-03-25

    (5) "key" is marked as undefined here:

    key=''
    
    #assert isinstance(evt,BoxSelectionEvent)  # uncomment this to get completions
    
    def drag(evt):
        global key
        assert isinstance(evt,BoxSelectionEvent) # Note completions don't work with this.
        k= evt.getPlane('keyChar')
    
     

    Last edit: Jeremy Faden 2026-03-25
MongoDB Logo MongoDB