Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up some IDE warnings #559

Merged
merged 9 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/tablib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
__version__ = None


from tablib.core import ( # noqa: F401
from .core import ( # noqa: F401
Databook,
Dataset,
InvalidDatasetType,
Expand Down
10 changes: 5 additions & 5 deletions src/tablib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
from copy import copy
from operator import itemgetter

from tablib.exceptions import (
from .exceptions import (
HeadersNeeded,
InvalidDatasetIndex,
InvalidDatasetType,
InvalidDimensions,
UnsupportedFormat,
)
from tablib.formats import registry
from tablib.utils import normalize_input
from .formats import registry
from .utils import normalize_input

__title__ = 'tablib'
__author__ = 'Kenneth Reitz'
Expand Down Expand Up @@ -75,7 +75,7 @@ def insert(self, index, value):
self._row.insert(index, value)

def __contains__(self, item):
return (item in self._row)
return item in self._row

@property
def tuple(self):
Expand All @@ -93,7 +93,7 @@ def has_tag(self, tag):
if tag is None:
return False
elif isinstance(tag, str):
return (tag in self.tags)
return tag in self.tags
else:
return bool(len(set(tag) & set(self.tags)))

Expand Down
7 changes: 3 additions & 4 deletions src/tablib/formats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
from importlib import import_module
from importlib.util import find_spec

from tablib.exceptions import UnsupportedFormat
from tablib.utils import normalize_input

from ..exceptions import UnsupportedFormat
from ..utils import normalize_input
from ._csv import CSVFormat
from ._json import JSONFormat
from ._tsv import TSVFormat
Expand Down Expand Up @@ -69,7 +68,7 @@ class Registry:
_formats = OrderedDict()

def register(self, key, format_or_path):
from tablib.core import Databook, Dataset
from ..core import Databook, Dataset

# Create Databook.<format> read or read/write properties
setattr(Databook, key, ImportExportBookDescriptor(key, format_or_path))
Expand Down
6 changes: 3 additions & 3 deletions src/tablib/formats/_dbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import os
import tempfile

from tablib.packages.dbfpy import dbf, dbfnew
from tablib.packages.dbfpy import record as dbfrecord
from ..packages.dbfpy import dbf, dbfnew
from ..packages.dbfpy import record as dbfrecord


class DBFFormat:
Expand Down Expand Up @@ -46,7 +46,7 @@ def export_set(cls, dataset):
return stream.getvalue()

@classmethod
def import_set(cls, dset, in_stream, headers=True):
def import_set(cls, dset, in_stream):
"""Returns a dataset from a DBF stream."""

dset.wipe()
Expand Down
2 changes: 1 addition & 1 deletion src/tablib/formats/_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def detect(cls, stream):
return False

@classmethod
def export_set(cls, dset, index=None):
def export_set(cls, dset):
"""Returns DataFrame representation of DataBook."""
if DataFrame is None:
raise NotImplementedError(
Expand Down
2 changes: 1 addition & 1 deletion src/tablib/formats/_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def export_book(cls, databook):
return result

@classmethod
def import_set(cls, dset, in_stream, table_id=None, **kwargs):
def import_set(cls, dset, in_stream, table_id=None):
"""Returns dataset from HTML content."""

dset.wipe()
Expand Down
6 changes: 3 additions & 3 deletions src/tablib/formats/_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ def _serialize_row(cls, row):
return 6 * ' ' + ' & '.join(new_row) + ' \\\\'

@classmethod
def _escape_tex_reserved_symbols(cls, input):
def _escape_tex_reserved_symbols(cls, string):
"""Escapes all TeX reserved symbols ('_', '~', etc.) in a string.

:param input: String to escape
:param string: String to escape
"""
def replace(match):
return cls.TEX_RESERVED_SYMBOLS_MAP[match.group()]
return cls.TEX_RESERVED_SYMBOLS_RE.sub(replace, input)
return cls.TEX_RESERVED_SYMBOLS_RE.sub(replace, string)
2 changes: 1 addition & 1 deletion src/tablib/formats/_ods.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def export_book(cls, databook):
wb.automaticstyles.addElement(bold)

for i, dset in enumerate(databook._datasets):
ws = table.Table(name=dset.title if dset.title else 'Sheet%s' % (i))
ws = table.Table(name=dset.title if dset.title else f"Sheet{i}")
wb.spreadsheet.addElement(ws)
cls.dset_sheet(dset, ws)

Expand Down
2 changes: 1 addition & 1 deletion src/tablib/formats/_xls.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def export_book(cls, databook):
wb = xlwt.Workbook(encoding='utf8')

for i, dset in enumerate(databook._datasets):
ws = wb.add_sheet(dset.title if dset.title else 'Sheet%s' % (i))
ws = wb.add_sheet(dset.title if dset.title else f"Sheet{i}")

cls.dset_sheet(dset, ws)

Expand Down
9 changes: 5 additions & 4 deletions src/tablib/formats/_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ def export_set(cls, dataset, freeze_panes=True, invalid_char_subst="-", escape=F

If ``freeze_panes`` is True, Export will freeze panes only after first line.

If ``dataset.title`` contains characters which are considered invalid for an XLSX file
sheet name (http://www.excelcodex.com/2012/06/worksheets-naming-conventions/), they will
be replaced with ``invalid_char_subst``.
If ``dataset.title`` contains characters which are
considered invalid for an XLSX file sheet name
(https://web.archive.org/web/20230323081941/https://www.excelcodex.com/2012/06/worksheets-naming-conventions/),
they will be replaced with ``invalid_char_subst``.

If ``escape`` is True, formulae will have the leading '=' character removed.
This is a security measure to prevent formulae from executing by default
Expand Down Expand Up @@ -75,7 +76,7 @@ def export_book(cls, databook, freeze_panes=True, invalid_char_subst="-", escape
ws = wb.create_sheet()
ws.title = (
safe_xlsx_sheet_title(dset.title, invalid_char_subst)
if dset.title else 'Sheet%s' % (i)
if dset.title else f"Sheet{i}"
)

cls.dset_sheet(dset, ws, freeze_panes=freeze_panes, escape=escape)
Expand Down
4 changes: 2 additions & 2 deletions src/tablib/packages/dbfpy/dbfnew.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
TODO:
- handle Memo fields.
- check length of the fields according to the
`http://www.clicketyclick.dk/databases/xbase/format/data_types.html`
`https://www.clicketyclick.dk/databases/xbase/format/data_types.html`

"""
"""History (most recent first)
Expand Down Expand Up @@ -80,7 +80,7 @@ def __init__(self, name, type, len=None, dec=0):
self.cls = _cls

def getDbfField(self):
"Return `DbfFieldDef` instance from the current definition."
"""Return `DbfFieldDef` instance from the current definition."""
return self.cls(self.name, self.len, self.dec)

def appendToHeader(self, dbfh):
Expand Down
8 changes: 4 additions & 4 deletions src/tablib/packages/dbfpy/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class DbfFieldDef:

Child classes must override ``type`` class attribute to provide datatype
information of the field definition. For more info about types visit
`http://www.clicketyclick.dk/databases/xbase/format/data_types.html`
`https://www.clicketyclick.dk/databases/xbase/format/data_types.html`

Also child classes must override ``defaultValue`` field to provide
default value for the field value.
Expand All @@ -66,7 +66,7 @@ class DbfFieldDef:
length = None

# field type. for more information about fields types visit
# `http://www.clicketyclick.dk/databases/xbase/format/data_types.html`
# `https://www.clicketyclick.dk/databases/xbase/format/data_types.html`
# must be overridden in child classes
typeCode = None

Expand Down Expand Up @@ -96,7 +96,7 @@ def __init__(self, name, length=None, decimalCount=None,
# set fields
self.name = name
# FIXME: validate length according to the specification at
# http://www.clicketyclick.dk/databases/xbase/format/data_types.html
# https://www.clicketyclick.dk/databases/xbase/format/data_types.html
self.length = length
self.decimalCount = decimalCount
self.ignoreErrors = ignoreErrors
Expand Down Expand Up @@ -163,7 +163,7 @@ def fieldInfo(self):
Return value is a (name, type, length, decimals) tuple.

"""
return (self.name, self.typeCode, self.length, self.decimalCount)
return self.name, self.typeCode, self.length, self.decimalCount

def rawFromRecord(self, record):
"""Return a "raw" field value from the record string."""
Expand Down
8 changes: 4 additions & 4 deletions tests/test_tablib.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def test_add_column_with_header_and_headers_only_exist(self):
data.headers = ['first_name']
# no data

new_col = ('allen')
new_col = 'allen'

def append_col_callable():
data.append_col(new_col, header='middle_name')
Expand Down Expand Up @@ -292,9 +292,9 @@ def test_datetime_append(self):

@pytest.mark.skipif(pandas is None, reason="pandas is not installed")
def test_separator_append(self):
for a in range(3):
for _ in range(3):
data.append_separator('foobar')
for a in range(5):
for _ in range(5):
data.append(['asdf', 'asdf', 'asdf'])
self._test_export_data_in_all_formats(data)

Expand Down Expand Up @@ -717,7 +717,7 @@ def test_html_import_table_id(self):

# If the id is not found, an error is raised
with self.assertRaises(ValueError) as exc:
dataset = tablib.import_set(html_input, format="html", table_id="notfound")
tablib.import_set(html_input, format="html", table_id="notfound")
self.assertEqual('No <table> found with id="notfound" in input HTML', str(exc.exception))


Expand Down
Loading