“Expected type 'Union[str, bytearray]' got 'int' instead” warning in write method

后端 未结 1 610
野趣味
野趣味 2021-01-04 09:29

My script writes to file chunk by chunk, using pre-generated data patterns:

#  Data pattern generator    
def get_random_chunk_pattern():
            return          


        
相关标签:
1条回答
  • 2021-01-04 10:26

    Ignore this warning. The IDE is making a best guess (from limited information) as to what the data type will be at runtime, but it is guessing wrong. That is, it is fairly reasonable to expect that something multiplied by an int will result in an int if you don't know what that something actually is.

    If you really want to solve this then tell the IDE what you expect chunk.pattern to be by writing a doc string for your class (or using annotations to provide type hinting).

    eg.

    class DedupChunk:
        """
        :type _chunk_pattern: str
        ... other fields
        """
        ... # rest of class
    
    0 讨论(0)
提交回复
热议问题