
import csv

class EmptyCSVError(Exception):
    pass


class UnicodeDictReader(object):
    def __init__(self, file_or_str, encoding='utf8', **kwargs):
        self.encoding = encoding
        self.reader = csv.DictReader(file_or_str, **kwargs)

        if not self.reader.fieldnames:
            raise EmptyCSVError("No fieldnames in CSV reader: empty file?")

        self.keymap = dict((k, k.decode(encoding)) for k in self.reader.fieldnames)

    def __iter__(self):
        return (self._decode_row(row) for row in self.reader)

    def _decode_row(self, row):
        return dict(
            (self.keymap[k], self._decode_str(v)) for k, v in row.iteritems()
        )

    def _decode_str(self, s):
        if s is None:
            return None
        return s.decode(self.encoding)


import csv

class EmptyCSVError(Exception):
    pass


class UnicodeDictReader(object):
    def __init__(self, fp, encoding='utf8', **kwargs):
        self.encoding = encoding
        self.reader = csv.DictReader(fp, **kwargs)

        if not self.reader.fieldnames:
            raise EmptyCSVError("No fieldnames in CSV reader: empty file?")

        self.keymap = dict((k, k.decode(encoding)) for k in self.reader.fieldnames)

    def __iter__(self):
        return (self._decode_row(row) for row in self.reader)

    def _decode_row(self, row):
        return dict(
            (self.keymap[k], self._decode_str(v)) for k, v in row.iteritems()
        )

    def _decode_str(self, s):
        if s is None:
            return None
        return s.decode(self.encoding)

Rename misleading parameter name: UnicodeDictReader should have the same interface as csv.DictReader
Rename misleading parameter name: UnicodeDictReader should have the same interface as csv.DictReader

  
  import csv
  
  class EmptyCSVError(Exception):
      pass
  
  
  class UnicodeDictReader(object):
-     def __init__(self, file_or_str, encoding='utf8', **kwargs):
+     def __init__(self, fp, encoding='utf8', **kwargs):
          self.encoding = encoding
-         self.reader = csv.DictReader(file_or_str, **kwargs)
+         self.reader = csv.DictReader(fp, **kwargs)
  
          if not self.reader.fieldnames:
              raise EmptyCSVError("No fieldnames in CSV reader: empty file?")
  
          self.keymap = dict((k, k.decode(encoding)) for k in self.reader.fieldnames)
  
      def __iter__(self):
          return (self._decode_row(row) for row in self.reader)
  
      def _decode_row(self, row):
          return dict(
              (self.keymap[k], self._decode_str(v)) for k, v in row.iteritems()
          )
  
      def _decode_str(self, s):
          if s is None:
              return None
          return s.decode(self.encoding)
  
Rename misleading parameter name: UnicodeDictReader should have the same interface as csv.DictReader
## Code Before:

import csv

class EmptyCSVError(Exception):
    pass


class UnicodeDictReader(object):
    def __init__(self, file_or_str, encoding='utf8', **kwargs):
        self.encoding = encoding
        self.reader = csv.DictReader(file_or_str, **kwargs)

        if not self.reader.fieldnames:
            raise EmptyCSVError("No fieldnames in CSV reader: empty file?")

        self.keymap = dict((k, k.decode(encoding)) for k in self.reader.fieldnames)

    def __iter__(self):
        return (self._decode_row(row) for row in self.reader)

    def _decode_row(self, row):
        return dict(
            (self.keymap[k], self._decode_str(v)) for k, v in row.iteritems()
        )

    def _decode_str(self, s):
        if s is None:
            return None
        return s.decode(self.encoding)

## Instruction:
Rename misleading parameter name: UnicodeDictReader should have the same interface as csv.DictReader
## Code After:

import csv

class EmptyCSVError(Exception):
    pass


class UnicodeDictReader(object):
    def __init__(self, fp, encoding='utf8', **kwargs):
        self.encoding = encoding
        self.reader = csv.DictReader(fp, **kwargs)

        if not self.reader.fieldnames:
            raise EmptyCSVError("No fieldnames in CSV reader: empty file?")

        self.keymap = dict((k, k.decode(encoding)) for k in self.reader.fieldnames)

    def __iter__(self):
        return (self._decode_row(row) for row in self.reader)

    def _decode_row(self, row):
        return dict(
            (self.keymap[k], self._decode_str(v)) for k, v in row.iteritems()
        )

    def _decode_str(self, s):
        if s is None:
            return None
        return s.decode(self.encoding)
