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

Update pylint #304

Merged
merged 3 commits into from
Jun 20, 2021
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
10 changes: 6 additions & 4 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ enable= E0001,E0100,E0101,E0102,E0103,E0104,E0105,E0106,E0107,E0110,
E0702,E0703,E0704,E0710,E0711,E0712,E1003,E1102,E1111,E0112,
E1120,E1121,E1123,E1124,E1125,E1126,E1127,E1132,E1200,E1201,
E1205,E1206,E1300,E1301,E1302,E1303,E1304,E1305,E1306,
C0123,C0200,C0303,C1001,
C0123,C0200,C0303,C0411,C1001,
W0101,W0102,W0104,W0105,W0106,W0107,W0108,W0109,W0110,W0120,
W0122,W0124,W0150,W0199,W0221,W0222,W0233,W0404,W0410,W0601,
W0602,W0604,W0611,W0612,W0622,W0623,W0702,W0705,W0711,W1300,
W1301,W1302,W1303,,W1305,W1306,W1307
W1301,W1302,W1303,W1305,W1306,W1307
R0102,R0202,R0203


Expand Down Expand Up @@ -112,7 +112,9 @@ evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / stateme
[BASIC]

# Good variable names which should always be accepted, separated by a comma
good-names=i,j,k,ex,Run,_
good-names=i,j,k,ex,Run,_,x,y,w,h,d,c,id,it

allowed-redefined-builtins=id,format,dir

# Bad variable names which should always be refused, separated by a comma
bad-names=foo,bar,baz,toto,tutu,tata
Expand Down Expand Up @@ -300,7 +302,7 @@ ignored-classes=optparse.Values,thread._local,_thread._local
# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E1101 when accessed. Python regular
# expressions are accepted.
generated-members=
generated-members=on_error

# List of decorators that produce context managers, such as
# contextlib.contextmanager. Add to this list to register other decorators that
Expand Down
15 changes: 9 additions & 6 deletions datumaro/components/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#
# SPDX-License-Identifier: MIT

#pylint: disable=redefined-builtin

from contextlib import contextmanager
from enum import Enum, auto
from typing import Iterable, Iterator, Optional, Tuple, Union, Dict, List
Expand All @@ -18,7 +16,8 @@
IExtractor, LabelCategories, AnnotationType, DatasetItem,
DEFAULT_SUBSET_NAME, Transform)
from datumaro.components.environment import Environment
from datumaro.components.errors import DatumaroError, RepeatedItemError
from datumaro.components.errors import (CategoriesRedefinedError,
DatumaroError, RepeatedItemError)
from datumaro.util import error_rollback
from datumaro.util.log_utils import logging_disabled

Expand Down Expand Up @@ -78,7 +77,7 @@ def subsets(self):

class DatasetItemStorageDatasetView(IDataset):
class Subset(IDataset):
def __init__(self, parent, name):
def __init__(self, parent: 'DatasetItemStorageDatasetView', name: str):
super().__init__()
self.parent = parent
self.name = name
Expand Down Expand Up @@ -319,6 +318,11 @@ def categories(self) -> CategoriesInfo:
else:
return self._source.categories()

def define_categories(self, categories: CategoriesInfo):
if self._categories or self._source is not None:
raise CategoriesRedefinedError()
self._categories = categories

def put(self, item):
is_new = self._storage.put(item)

Expand Down Expand Up @@ -459,8 +463,7 @@ def __init__(self, source: IDataset = None,
self._source_path = None

def define_categories(self, categories: Dict):
assert not self._data._categories and self._data._source is None
self._data._categories = categories
self._data.define_categories(categories)

def init_cache(self):
self._data.init_cache()
Expand Down
4 changes: 4 additions & 0 deletions datumaro/components/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class RepeatedItemError(DatasetError):
def __str__(self):
return "Item %s is repeated in the source sequence." % (self.item_id, )

class CategoriesRedefinedError(DatasetError):
def __str__(self):
return "Categories can only be set once for a dataset"

@attrs
class MismatchingImageInfoError(DatasetError):
a = attrib()
Expand Down
10 changes: 5 additions & 5 deletions datumaro/components/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
from enum import Enum, auto
from glob import iglob
from typing import Callable, Iterable, List, Dict, Optional
import numpy as np
import os
import os.path as osp

import attr
from attr import attrs, attrib
import attr
import numpy as np

from datumaro.util.image import Image
from datumaro.util.attrs_util import not_empty, default_if_none
Expand Down Expand Up @@ -541,7 +541,7 @@ def wrap(item, **kwargs):

CategoriesInfo = Dict[AnnotationType, Categories]

class IExtractor: #pylint: disable=redefined-builtin
class IExtractor:
def __iter__(self) -> Iterable[DatasetItem]:
raise NotImplementedError()

Expand Down Expand Up @@ -614,7 +614,7 @@ def categories(_):
def categories(self):
return {}

def get(self, id, subset=None): #pylint: disable=redefined-builtin
def get(self, id, subset=None):
subset = subset or DEFAULT_SUBSET_NAME
for item in self:
if item.id == id and item.subset == subset:
Expand All @@ -638,7 +638,7 @@ def __iter__(self):
def __len__(self):
return len(self._items)

def get(self, id, subset=None): #pylint: disable=redefined-builtin
def get(self, id, subset=None):
assert subset == self._subset, '%s != %s' % (subset, self._subset)
return super().get(id, subset or self._subset)

Expand Down
11 changes: 4 additions & 7 deletions datumaro/components/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __len__(self):
def categories(self):
return self.parent.categories()

def get(self, id, subset=None): #pylint: disable=redefined-builtin
def get(self, id, subset=None):
subset = subset or self.name
assert subset == self.name, '%s != %s' % (subset, self.name)
return super().get(id, subset)
Expand Down Expand Up @@ -137,15 +137,13 @@ def categories(self):
def __len__(self):
return sum(len(s) for s in self._subsets.values())

def get(self, id, subset=None, \
path=None): #pylint: disable=redefined-builtin
def get(self, id, subset=None, path=None):
if path:
source = path[0]
return self._sources[source].get(id=id, subset=subset)
return self._subsets.get(subset, {}).get(id)

def put(self, item, id=None, subset=None, \
path=None): #pylint: disable=redefined-builtin
def put(self, item, id=None, subset=None, path=None):
if path is None:
path = item.path

Expand Down Expand Up @@ -277,8 +275,7 @@ def categories(_):

return self.transform(_DatasetFilter)

def export(self, save_dir: str, format, \
**kwargs): #pylint: disable=redefined-builtin
def export(self, save_dir: str, format, **kwargs):
dataset = Dataset.from_extractors(self, env=self.env)
dataset.export(save_dir, format, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion datumaro/plugins/voc_format/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
)


def _convert_attr(name, attributes, type_conv, default=None, warn=True):
def _convert_attr(name, attributes, type_conv, default=None):
d = object()
value = attributes.get(name, d)
if value is d:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_voc_format.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from collections import OrderedDict
from functools import partial
import numpy as np
from unittest import TestCase
import os
import os.path as osp

from unittest import TestCase
import numpy as np

from datumaro.components.extractor import (Extractor, DatasetItem,
AnnotationType, Label, Bbox, Mask, LabelCategories,
Expand Down