pythonmethodspycharmfalse-positive

PyCharm thinks variable is not used but clearly is inside class method?


For some reason PyCharm is telling me that 3 of my 5 list are not used in my function but they in fact are being used in the function and the code completes with the expected results.

This is odd behavior. Is this a bug?

I have seen some issues for f-strings reporting false positives but I do not think this is the same issue here.

   def filter_for_vzb_vzt(self, query_results):
        vzb_list = []
        vzt_list = []
        vzt_analyst_tkr = []
        vzb_analyst_tkr = []
        vzb_lpc_analyst_tkr = []

        with open('./Files/{}.json'.format('VZT_ACNA_LIST'), 'r') as df:
            vzt_analyst_tkr = json.load(df)

        with open('./Files/{}.json'.format('VZB_TAX_ACNA_LIST'), 'r') as df:
            vzb_analyst_tkr = json.load(df)

        with open('./Files/{}.json'.format('VZB_LPC_ACNA_LIST'), 'r') as df:
            vzb_lpc_analyst_tkr = json.load(df)

        self.process_vzb_mass(vzb_list, vzb_analyst_tkr, vzb_lpc_analyst_tkr)
        self.process_vzt_mass(vzt_list, vzt_analyst_tkr)
        self.active_time = False

enter image description here


Solution

  • You are indeed not using those values. Read carefully the message:

    local variable <...> value is not used

    PyCharm is being very specific - you are assigning these three variables a new list with

    <...> = json...
    

    The original empty lists that these variables pointed to are then discarded.

    These assignments are not conditional, so you will never use those empty lists - PyCharm is warning you you are not using the empty lists, rather than the variables themselves. You should probably just delete those lines - common practice is to first define variables with values that will actually be used.