gurudesh/pytracebugs huggingface dataset:
# Buggy code
def title(self):
    return _("Recent changes in %s") % settings.SITE_TITLE


# Traceback (AttributeError)
Traceback (most recent call last):

File "/srv/weblate/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/srv/weblate/src/weblate/weblate/trans/views.py", line 1395, in translate
saved = unit.save_backend(request)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 2478, in save_backend
self.translation.update_lock(request)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1463, in update_lock
self.create_lock(request.user)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1434, in create_lock
self.update_lock_time(explicit, is_new)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1443, in update_lock_time
seconds = settings.AUTO_LOCK_TIME
File "/srv/weblate/local/lib/python2.7/site-packages/django/utils/functional.py", line 185, in inner
return func(self._wrapped, *args)
AttributeError: 'Settings' object has no attribute 'AUTO_LOCK_TIME'

# Fixed code
def title(self):
    return _("Recent changes in %s") % appsettings.SITE_TITLE
# Buggy code
def description(self):
    return _("All recent changes made using Weblate in %s.") % settings.SITE_TITLE


# Traceback (AttributeError)
Traceback (most recent call last):

File "/srv/weblate/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/srv/weblate/src/weblate/weblate/trans/views.py", line 1395, in translate
saved = unit.save_backend(request)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 2478, in save_backend
self.translation.update_lock(request)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1463, in update_lock
self.create_lock(request.user)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1434, in create_lock
self.update_lock_time(explicit, is_new)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1443, in update_lock_time
seconds = settings.AUTO_LOCK_TIME
File "/srv/weblate/local/lib/python2.7/site-packages/django/utils/functional.py", line 185, in inner
return func(self._wrapped, *args)
AttributeError: 'Settings' object has no attribute 'AUTO_LOCK_TIME'

# Fixed code
def description(self):
    return _("All recent changes made using Weblate in %s.") % appsettings.SITE_TITLE
# Buggy code
def add_to_index(self, unit, source=True):
    """
    Updates/Adds to all indices given unit.
    """
    if settings.OFFLOAD_INDEXING:
        from weblate.trans.models import IndexUpdate

        IndexUpdate.objects.get_or_create(unit=unit, source=source)
        return

    writer_target = FULLTEXT_INDEX.target_writer(unit.translation.language.code)
    writer_source = FULLTEXT_INDEX.source_writer()

    if source:
        self.add_to_source_index(
            unit.checksum, unit.source, unit.context, writer_source
        )
    self.add_to_target_index(unit.checksum, unit.target, writer_target)


# Traceback (AttributeError)
Traceback (most recent call last):

File "/srv/weblate/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/srv/weblate/src/weblate/weblate/trans/views.py", line 1395, in translate
saved = unit.save_backend(request)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 2478, in save_backend
self.translation.update_lock(request)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1463, in update_lock
self.create_lock(request.user)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1434, in create_lock
self.update_lock_time(explicit, is_new)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1443, in update_lock_time
seconds = settings.AUTO_LOCK_TIME
File "/srv/weblate/local/lib/python2.7/site-packages/django/utils/functional.py", line 185, in inner
return func(self._wrapped, *args)
AttributeError: 'Settings' object has no attribute 'AUTO_LOCK_TIME'

# Fixed code
def add_to_index(self, unit, source=True):
    """
    Updates/Adds to all indices given unit.
    """
    if appsettings.OFFLOAD_INDEXING:
        from weblate.trans.models import IndexUpdate

        IndexUpdate.objects.get_or_create(unit=unit, source=source)
        return

    writer_target = FULLTEXT_INDEX.target_writer(unit.translation.language.code)
    writer_source = FULLTEXT_INDEX.source_writer()

    if source:
        self.add_to_source_index(
            unit.checksum, unit.source, unit.context, writer_source
        )
    self.add_to_target_index(unit.checksum, unit.target, writer_target)
# Buggy code
def search(self, query, source=True, context=True, translation=True, checksums=False):
    """
    Performs full text search on defined set of fields.

    Returns queryset unless checksums is set.
    """
    ret = set()
    if source or context:
        with FULLTEXT_INDEX.source_searcher(not settings.OFFLOAD_INDEXING) as searcher:
            if source:
                results = self.__search(searcher, "source", SOURCE_SCHEMA, query)
                ret = ret.union(results)
            if context:
                results = self.__search(searcher, "context", SOURCE_SCHEMA, query)
                ret = ret.union(results)

    if translation:
        sample = self.all()[0]
        with FULLTEXT_INDEX.target_searcher(
            sample.translation.language.code, not settings.OFFLOAD_INDEXING
        ) as searcher:
            results = self.__search(searcher, "target", TARGET_SCHEMA, query)
            ret = ret.union(results)

    if checksums:
        return ret

    return self.filter(checksum__in=ret)


# Traceback (AttributeError)
Traceback (most recent call last):

File "/srv/weblate/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/srv/weblate/src/weblate/weblate/trans/views.py", line 1395, in translate
saved = unit.save_backend(request)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 2478, in save_backend
self.translation.update_lock(request)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1463, in update_lock
self.create_lock(request.user)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1434, in create_lock
self.update_lock_time(explicit, is_new)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1443, in update_lock_time
seconds = settings.AUTO_LOCK_TIME
File "/srv/weblate/local/lib/python2.7/site-packages/django/utils/functional.py", line 185, in inner
return func(self._wrapped, *args)
AttributeError: 'Settings' object has no attribute 'AUTO_LOCK_TIME'

# Fixed code
def search(self, query, source=True, context=True, translation=True, checksums=False):
    """
    Performs full text search on defined set of fields.

    Returns queryset unless checksums is set.
    """
    ret = set()
    if source or context:
        with FULLTEXT_INDEX.source_searcher(
            not appsettings.OFFLOAD_INDEXING
        ) as searcher:
            if source:
                results = self.__search(searcher, "source", SOURCE_SCHEMA, query)
                ret = ret.union(results)
            if context:
                results = self.__search(searcher, "context", SOURCE_SCHEMA, query)
                ret = ret.union(results)

    if translation:
        sample = self.all()[0]
        with FULLTEXT_INDEX.target_searcher(
            sample.translation.language.code, not appsettings.OFFLOAD_INDEXING
        ) as searcher:
            results = self.__search(searcher, "target", TARGET_SCHEMA, query)
            ret = ret.union(results)

    if checksums:
        return ret

    return self.filter(checksum__in=ret)
# Buggy code
def create_source_index():
    return create_in(settings.WHOOSH_INDEX, schema=SOURCE_SCHEMA, indexname="source")


# Traceback (AttributeError)
Traceback (most recent call last):

File "/srv/weblate/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/srv/weblate/src/weblate/weblate/trans/views.py", line 1395, in translate
saved = unit.save_backend(request)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 2478, in save_backend
self.translation.update_lock(request)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1463, in update_lock
self.create_lock(request.user)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1434, in create_lock
self.update_lock_time(explicit, is_new)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1443, in update_lock_time
seconds = settings.AUTO_LOCK_TIME
File "/srv/weblate/local/lib/python2.7/site-packages/django/utils/functional.py", line 185, in inner
return func(self._wrapped, *args)
AttributeError: 'Settings' object has no attribute 'AUTO_LOCK_TIME'

# Fixed code
def create_source_index():
    return create_in(appsettings.WHOOSH_INDEX, schema=SOURCE_SCHEMA, indexname="source")
# Buggy code
def create_target_index(lang):
    return create_in(
        settings.WHOOSH_INDEX, schema=TARGET_SCHEMA, indexname="target-%s" % lang
    )


# Traceback (AttributeError)
Traceback (most recent call last):

File "/srv/weblate/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/srv/weblate/src/weblate/weblate/trans/views.py", line 1395, in translate
saved = unit.save_backend(request)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 2478, in save_backend
self.translation.update_lock(request)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1463, in update_lock
self.create_lock(request.user)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1434, in create_lock
self.update_lock_time(explicit, is_new)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1443, in update_lock_time
seconds = settings.AUTO_LOCK_TIME
File "/srv/weblate/local/lib/python2.7/site-packages/django/utils/functional.py", line 185, in inner
return func(self._wrapped, *args)
AttributeError: 'Settings' object has no attribute 'AUTO_LOCK_TIME'

# Fixed code
def create_target_index(lang):
    return create_in(
        appsettings.WHOOSH_INDEX, schema=TARGET_SCHEMA, indexname="target-%s" % lang
    )
# Buggy code
def create_index(sender=None, **kwargs):
    if not os.path.exists(settings.WHOOSH_INDEX):
        os.mkdir(settings.WHOOSH_INDEX)
        create_source_index()


# Traceback (AttributeError)
Traceback (most recent call last):

File "/srv/weblate/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/srv/weblate/src/weblate/weblate/trans/views.py", line 1395, in translate
saved = unit.save_backend(request)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 2478, in save_backend
self.translation.update_lock(request)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1463, in update_lock
self.create_lock(request.user)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1434, in create_lock
self.update_lock_time(explicit, is_new)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1443, in update_lock_time
seconds = settings.AUTO_LOCK_TIME
File "/srv/weblate/local/lib/python2.7/site-packages/django/utils/functional.py", line 185, in inner
return func(self._wrapped, *args)
AttributeError: 'Settings' object has no attribute 'AUTO_LOCK_TIME'

# Fixed code
def create_index(sender=None, **kwargs):
    if not os.path.exists(appsettings.WHOOSH_INDEX):
        os.mkdir(appsettings.WHOOSH_INDEX)
        create_source_index()
# Buggy code
def source(self):
    """
    Returns source index.
    """
    if self._source is None:
        try:
            self._source = open_dir(settings.WHOOSH_INDEX, indexname="source")
        except whoosh.index.EmptyIndexError:
            self._source = create_source_index()
        except IOError:
            # eg. path does not exist
            self._source = create_source_index()
    return self._source


# Traceback (AttributeError)
Traceback (most recent call last):

File "/srv/weblate/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/srv/weblate/src/weblate/weblate/trans/views.py", line 1395, in translate
saved = unit.save_backend(request)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 2478, in save_backend
self.translation.update_lock(request)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1463, in update_lock
self.create_lock(request.user)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1434, in create_lock
self.update_lock_time(explicit, is_new)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1443, in update_lock_time
seconds = settings.AUTO_LOCK_TIME
File "/srv/weblate/local/lib/python2.7/site-packages/django/utils/functional.py", line 185, in inner
return func(self._wrapped, *args)
AttributeError: 'Settings' object has no attribute 'AUTO_LOCK_TIME'

# Fixed code
def source(self):
    """
    Returns source index.
    """
    if self._source is None:
        try:
            self._source = open_dir(appsettings.WHOOSH_INDEX, indexname="source")
        except whoosh.index.EmptyIndexError:
            self._source = create_source_index()
        except IOError:
            # eg. path does not exist
            self._source = create_source_index()
    return self._source
# Buggy code
def target(self, lang):
    """
    Returns target index for given language.
    """
    if not lang in self._target:
        try:
            self._target[lang] = open_dir(
                settings.WHOOSH_INDEX, indexname="target-%s" % lang
            )
        except whoosh.index.EmptyIndexError:
            self._target[lang] = create_target_index(lang)
    return self._target[lang]


# Traceback (AttributeError)
Traceback (most recent call last):

File "/srv/weblate/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/srv/weblate/src/weblate/weblate/trans/views.py", line 1395, in translate
saved = unit.save_backend(request)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 2478, in save_backend
self.translation.update_lock(request)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1463, in update_lock
self.create_lock(request.user)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1434, in create_lock
self.update_lock_time(explicit, is_new)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1443, in update_lock_time
seconds = settings.AUTO_LOCK_TIME
File "/srv/weblate/local/lib/python2.7/site-packages/django/utils/functional.py", line 185, in inner
return func(self._wrapped, *args)
AttributeError: 'Settings' object has no attribute 'AUTO_LOCK_TIME'

# Fixed code
def target(self, lang):
    """
    Returns target index for given language.
    """
    if not lang in self._target:
        try:
            self._target[lang] = open_dir(
                appsettings.WHOOSH_INDEX, indexname="target-%s" % lang
            )
        except whoosh.index.EmptyIndexError:
            self._target[lang] = create_target_index(lang)
    return self._target[lang]
# Buggy code
def site_title(value):
    """
    Returns site title
    """
    return settings.SITE_TITLE


# Traceback (AttributeError)
Traceback (most recent call last):

File "/srv/weblate/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/srv/weblate/src/weblate/weblate/trans/views.py", line 1395, in translate
saved = unit.save_backend(request)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 2478, in save_backend
self.translation.update_lock(request)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1463, in update_lock
self.create_lock(request.user)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1434, in create_lock
self.update_lock_time(explicit, is_new)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1443, in update_lock_time
seconds = settings.AUTO_LOCK_TIME
File "/srv/weblate/local/lib/python2.7/site-packages/django/utils/functional.py", line 185, in inner
return func(self._wrapped, *args)
AttributeError: 'Settings' object has no attribute 'AUTO_LOCK_TIME'

# Fixed code
def site_title(value):
    """
    Returns site title
    """
    return appsettings.SITE_TITLE
# Buggy code
def import_plugins() -> None:
    """
    Imports the plugins found with `discover_plugins()`.
    """
    for module_name in DEFAULT_PLUGINS:
        try:
            # For default plugins we recursively import everything.
            import_module_and_submodules(module_name)
            logger.info("Plugin %s available", module_name)
        except ModuleNotFoundError:
            pass
    for module_name in discover_plugins():
        try:
            importlib.import_module(module_name)
            logger.info("Plugin %s available", module_name)
        except ModuleNotFoundError as e:
            logger.error(f"Plugin {module_name} could not be loaded: {e}")


# Traceback (ModuleNotFoundError)
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/xxx/anaconda3/envs/allennlp1.0/lib/python3.7/multiprocessing/spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "/home/xxx/anaconda3/envs/allennlp1.0/lib/python3.7/multiprocessing/spawn.py", line 115, in _main
self = reduction.pickle.load(from_parent)
ModuleNotFoundError: No module named 'my_text_classifier'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/xxx/anaconda3/envs/allennlp1.0/lib/python3.7/multiprocessing/spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "/home/xxx/anaconda3/envs/allennlp1.0/lib/python3.7/multiprocessing/spawn.py", line 115, in _main
self = reduction.pickle.load(from_parent)
ModuleNotFoundError: No module named 'my_text_classifier'

# Fixed code
def import_plugins() -> None:
    """
    Imports the plugins found with `discover_plugins()`.
    """

    # Workaround for a presumed Python issue where spawned processes can't find modules in the current directory.
    cwd = os.getcwd()
    if cwd not in sys.path:
        sys.path.append(cwd)

    for module_name in DEFAULT_PLUGINS:
        try:
            # For default plugins we recursively import everything.
            import_module_and_submodules(module_name)
            logger.info("Plugin %s available", module_name)
        except ModuleNotFoundError:
            pass
    for module_name in discover_plugins():
        try:
            importlib.import_module(module_name)
            logger.info("Plugin %s available", module_name)
        except ModuleNotFoundError as e:
            logger.error(f"Plugin {module_name} could not be loaded: {e}")
# Buggy code
def infer_params(cls: Type[T], constructor: Callable[..., T] = None):
    if constructor is None:
        constructor = cls.__init__

    signature = inspect.signature(constructor)
    parameters = dict(signature.parameters)

    has_kwargs = False
    for param in parameters.values():
        if param.kind == param.VAR_KEYWORD:
            has_kwargs = True

    if not has_kwargs:
        return parameters

    # "mro" is "method resolution order".  The first one is the current class, the next is the
    # first superclass, and so on.  We take the first superclass we find that inherits from
    # FromParams.
    super_class = None
    for super_class_candidate in cls.mro()[1:]:
        if issubclass(super_class_candidate, FromParams):
            super_class = super_class_candidate
            break
    if not super_class:
        raise RuntimeError("found a kwargs parameter with no inspectable super class")
    super_parameters = infer_params(super_class)

    return {
        **super_parameters,
        **parameters,
    }  # Subclass parameters overwrite superclass ones


# Traceback (RuntimeError)
Traceback (most recent call last):
File "tmp.py", line 10, in <module>
Foo.from_params(Params({"a": 2, "b": "hi"}))
File "/Users/evanw/AllenAI/allennlp/allennlp/common/from_params.py", line 610, in from_params
kwargs = create_kwargs(constructor_to_inspect, cls, params, **extras)
File "/Users/evanw/AllenAI/allennlp/allennlp/common/from_params.py", line 163, in create_kwargs
parameters = infer_params(cls, constructor)
File "/Users/evanw/AllenAI/allennlp/allennlp/common/from_params.py", line 140, in infer_params
super_parameters = infer_params(super_class)
File "/Users/evanw/AllenAI/allennlp/allennlp/common/from_params.py", line 139, in infer_params
raise RuntimeError("found a kwargs parameter with no inspectable super class")
RuntimeError: found a kwargs parameter with no inspectable super class

# Fixed code
def infer_params(cls: Type[T], constructor: Callable[..., T] = None) -> Dict[str, Any]:
    if cls == FromParams:
        return {}
    if constructor is None:
        constructor = cls.__init__

    signature = inspect.signature(constructor)
    parameters = dict(signature.parameters)

    has_kwargs = False
    for param in parameters.values():
        if param.kind == param.VAR_KEYWORD:
            has_kwargs = True

    if not has_kwargs:
        return parameters

    # "mro" is "method resolution order".  The first one is the current class, the next is the
    # first superclass, and so on.  We take the first superclass we find that inherits from
    # FromParams.
    super_class = None
    for super_class_candidate in cls.mro()[1:]:
        if issubclass(super_class_candidate, FromParams):
            super_class = super_class_candidate
            break
    if super_class:
        super_parameters = infer_params(super_class)
    else:
        super_parameters = {}

    return {
        **super_parameters,
        **parameters,
    }  # Subclass parameters overwrite superclass ones
# Buggy code
def __call__(self, tensor: torch.Tensor, parameter_name: str, **kwargs) -> None:  # type: ignore
    # Select the new parameter name if it's being overridden
    if parameter_name in self.parameter_name_overrides:
        parameter_name = self.parameter_name_overrides[parameter_name]

    # If the size of the source and destination tensors are not the
    # same, then we need to raise an error
    source_weights = self.weights[parameter_name]
    if tensor.data.size() != source_weights.size():
        raise ConfigurationError(
            "Incompatible sizes found for parameter %s. "
            "Found %s and %s"
            % (parameter_name, tensor.data.size(), source_weights.size())
        )

    # Copy the parameters from the source to the destination
    tensor.data[:] = source_weights[:]


# Traceback (IndexError)
Traceback (most recent call last):
File "test.py", line 27, in <module>
applicator(net)
File "/Users/reiyw/.ghq/ghq/github.com/allenai/allennlp/allennlp/nn/initializers.py", line 482, in __call__
initializer(parameter, parameter_name=name)
File "/Users/reiyw/.ghq/ghq/github.com/allenai/allennlp/allennlp/nn/initializers.py", line 406, in __call__
tensor.data[:] = source_weights[:]
IndexError: slice() cannot be applied to a 0-dim tensor.

# Fixed code
def __call__(self, tensor: torch.Tensor, parameter_name: str, **kwargs) -> None:  # type: ignore
    # Select the new parameter name if it's being overridden
    if parameter_name in self.parameter_name_overrides:
        parameter_name = self.parameter_name_overrides[parameter_name]

    # If the size of the source and destination tensors are not the
    # same, then we need to raise an error
    source_weights = self.weights[parameter_name]
    if tensor.data.size() != source_weights.size():
        raise ConfigurationError(
            "Incompatible sizes found for parameter %s. "
            "Found %s and %s"
            % (parameter_name, tensor.data.size(), source_weights.size())
        )

    # Copy the parameters from the source to the destination
    tensor.data.copy_(source_weights.data)
# Buggy code
def get_posonlyargs(node: AnyFunctionDefAndLambda) -> List[ast.arg]:
    """
    Helper function to get posonlyargs in all version of python.

    This field was added in ``python3.8+``. And it was not present before.

    mypy also gives an error on this on older version of python::

        error: "arguments" has no attribute "posonlyargs"; maybe "kwonlyargs"?

    """
    return getattr(node.args, "posonlyargs", [])


# Traceback (AttributeError)
/Users/DBoger/PycharmProjects/project/.venv/bin/python -m flake8 project
Traceback (most recent call last):
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/checker.py", line 154, in run
visitor.run()
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/base.py", line 191, in run
self.visit(self.tree)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/base.py", line 186, in visit
return route_visit(self, tree)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/compat/routing.py", line 36, in route_visit
return getattr(
File "/Users/DBoger/.pyenv/versions/3.9.0b5/lib/python3.9/ast.py", line 408, in generic_visit
self.visit(item)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/base.py", line 186, in visit
return route_visit(self, tree)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/compat/routing.py", line 36, in route_visit
return getattr(
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/ast/complexity/annotations.py", line 34, in visit_any_function
self._check_function_annotations_complexity(node)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/ast/complexity/annotations.py", line 58, in _check_function_annotations_complexity
self._check_annotations_complexity(node, annotations)
File "/Users/DBoger/PycharmProjects/sellerly-profile/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/ast/complexity/annotations.py", line 67, in _check_annotations_complexity
complexity = get_annotation_compexity(annotation)
File "/Users/DBoger/PycharmProjects/sellerly-profile/.venv/lib/python3.9/site-packages/wemake_python_styleguide/logic/complexity/annotations.py", line 36, in get_annotation_compexity
annotation_node.slice.value,  # type: ignore
AttributeError: 'Tuple' object has no attribute 'value'

# Fixed code
def get_posonlyargs(node: AnyFunctionDefAndLambda) -> List[ast.arg]:
    """
    Function to get posonlyargs in all versions of python.

    This field was added in ``python3.8+``. And it was not present before.

    mypy also gives an error on this on older version of python::

        error: "arguments" has no attribute "posonlyargs"; maybe "kwonlyargs"?

    """
    return getattr(node.args, "posonlyargs", [])
# Buggy code
def is_same_slice(
    iterable: str,
    target: str,
    node: ast.Subscript,
) -> bool:
    """Used to tell when slice is identical to some pair of name/index."""
    return (
        source.node_to_string(node.value) == iterable
        and isinstance(node.slice, ast.Index)  # mypy is unhappy
        and source.node_to_string(node.slice.value) == target
    )


# Traceback (AttributeError)
/Users/DBoger/PycharmProjects/project/.venv/bin/python -m flake8 project
Traceback (most recent call last):
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/checker.py", line 154, in run
visitor.run()
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/base.py", line 191, in run
self.visit(self.tree)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/base.py", line 186, in visit
return route_visit(self, tree)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/compat/routing.py", line 36, in route_visit
return getattr(
File "/Users/DBoger/.pyenv/versions/3.9.0b5/lib/python3.9/ast.py", line 408, in generic_visit
self.visit(item)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/base.py", line 186, in visit
return route_visit(self, tree)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/compat/routing.py", line 36, in route_visit
return getattr(
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/ast/complexity/annotations.py", line 34, in visit_any_function
self._check_function_annotations_complexity(node)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/ast/complexity/annotations.py", line 58, in _check_function_annotations_complexity
self._check_annotations_complexity(node, annotations)
File "/Users/DBoger/PycharmProjects/sellerly-profile/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/ast/complexity/annotations.py", line 67, in _check_annotations_complexity
complexity = get_annotation_compexity(annotation)
File "/Users/DBoger/PycharmProjects/sellerly-profile/.venv/lib/python3.9/site-packages/wemake_python_styleguide/logic/complexity/annotations.py", line 36, in get_annotation_compexity
annotation_node.slice.value,  # type: ignore
AttributeError: 'Tuple' object has no attribute 'value'

# Fixed code
def is_same_slice(
    iterable: str,
    target: str,
    node: ast.Subscript,
) -> bool:
    """Used to tell when slice is identical to some pair of name/index."""
    return (
        source.node_to_string(node.value) == iterable
        and source.node_to_string(get_slice_expr(node)) == target
    )
# Buggy code
def _check_float_key(self, node: ast.Subscript) -> None:
    is_float_key = isinstance(node.slice, ast.Index) and self._is_float_key(node.slice)

    if is_float_key:
        self.add_violation(best_practices.FloatKeyViolation(node))


# Traceback (AttributeError)
/Users/DBoger/PycharmProjects/project/.venv/bin/python -m flake8 project
Traceback (most recent call last):
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/checker.py", line 154, in run
visitor.run()
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/base.py", line 191, in run
self.visit(self.tree)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/base.py", line 186, in visit
return route_visit(self, tree)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/compat/routing.py", line 36, in route_visit
return getattr(
File "/Users/DBoger/.pyenv/versions/3.9.0b5/lib/python3.9/ast.py", line 408, in generic_visit
self.visit(item)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/base.py", line 186, in visit
return route_visit(self, tree)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/compat/routing.py", line 36, in route_visit
return getattr(
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/ast/complexity/annotations.py", line 34, in visit_any_function
self._check_function_annotations_complexity(node)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/ast/complexity/annotations.py", line 58, in _check_function_annotations_complexity
self._check_annotations_complexity(node, annotations)
File "/Users/DBoger/PycharmProjects/sellerly-profile/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/ast/complexity/annotations.py", line 67, in _check_annotations_complexity
complexity = get_annotation_compexity(annotation)
File "/Users/DBoger/PycharmProjects/sellerly-profile/.venv/lib/python3.9/site-packages/wemake_python_styleguide/logic/complexity/annotations.py", line 36, in get_annotation_compexity
annotation_node.slice.value,  # type: ignore
AttributeError: 'Tuple' object has no attribute 'value'

# Fixed code
def _check_float_key(self, node: ast.Subscript) -> None:
    if self._is_float_key(get_slice_expr(node)):
        self.add_violation(best_practices.FloatKeyViolation(node))
# Buggy code
def _check_len_call(self, node: ast.Subscript) -> None:
    is_len_call = (
        isinstance(node.slice, ast.Index)
        and isinstance(node.slice.value, ast.BinOp)
        and isinstance(node.slice.value.op, ast.Sub)
        and self._is_wrong_len(
            node.slice.value,
            source.node_to_string(node.value),
        )
    )

    if is_len_call:
        self.add_violation(
            refactoring.ImplicitNegativeIndexViolation(node),
        )


# Traceback (AttributeError)
/Users/DBoger/PycharmProjects/project/.venv/bin/python -m flake8 project
Traceback (most recent call last):
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/checker.py", line 154, in run
visitor.run()
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/base.py", line 191, in run
self.visit(self.tree)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/base.py", line 186, in visit
return route_visit(self, tree)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/compat/routing.py", line 36, in route_visit
return getattr(
File "/Users/DBoger/.pyenv/versions/3.9.0b5/lib/python3.9/ast.py", line 408, in generic_visit
self.visit(item)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/base.py", line 186, in visit
return route_visit(self, tree)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/compat/routing.py", line 36, in route_visit
return getattr(
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/ast/complexity/annotations.py", line 34, in visit_any_function
self._check_function_annotations_complexity(node)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/ast/complexity/annotations.py", line 58, in _check_function_annotations_complexity
self._check_annotations_complexity(node, annotations)
File "/Users/DBoger/PycharmProjects/sellerly-profile/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/ast/complexity/annotations.py", line 67, in _check_annotations_complexity
complexity = get_annotation_compexity(annotation)
File "/Users/DBoger/PycharmProjects/sellerly-profile/.venv/lib/python3.9/site-packages/wemake_python_styleguide/logic/complexity/annotations.py", line 36, in get_annotation_compexity
annotation_node.slice.value,  # type: ignore
AttributeError: 'Tuple' object has no attribute 'value'

# Fixed code
def _check_len_call(self, node: ast.Subscript) -> None:
    node_slice = get_slice_expr(node)
    is_len_call = (
        isinstance(node_slice, ast.BinOp)
        and isinstance(node_slice.op, ast.Sub)
        and self._is_wrong_len(
            node_slice,
            source.node_to_string(node.value),
        )
    )

    if is_len_call:
        self.add_violation(
            refactoring.ImplicitNegativeIndexViolation(node),
        )
# Buggy code
def _is_float_key(self, node: ast.Index) -> bool:
    real_node = operators.unwrap_unary_node(node.value)
    return isinstance(real_node, ast.Num) and isinstance(real_node.n, float)


# Traceback (AttributeError)
/Users/DBoger/PycharmProjects/project/.venv/bin/python -m flake8 project
Traceback (most recent call last):
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/checker.py", line 154, in run
visitor.run()
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/base.py", line 191, in run
self.visit(self.tree)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/base.py", line 186, in visit
return route_visit(self, tree)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/compat/routing.py", line 36, in route_visit
return getattr(
File "/Users/DBoger/.pyenv/versions/3.9.0b5/lib/python3.9/ast.py", line 408, in generic_visit
self.visit(item)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/base.py", line 186, in visit
return route_visit(self, tree)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/compat/routing.py", line 36, in route_visit
return getattr(
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/ast/complexity/annotations.py", line 34, in visit_any_function
self._check_function_annotations_complexity(node)
File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/ast/complexity/annotations.py", line 58, in _check_function_annotations_complexity
self._check_annotations_complexity(node, annotations)
File "/Users/DBoger/PycharmProjects/sellerly-profile/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/ast/complexity/annotations.py", line 67, in _check_annotations_complexity
complexity = get_annotation_compexity(annotation)
File "/Users/DBoger/PycharmProjects/sellerly-profile/.venv/lib/python3.9/site-packages/wemake_python_styleguide/logic/complexity/annotations.py", line 36, in get_annotation_compexity
annotation_node.slice.value,  # type: ignore
AttributeError: 'Tuple' object has no attribute 'value'

# Fixed code
def _is_float_key(self, node: ast.expr) -> bool:
    real_node = operators.unwrap_unary_node(node)
    return isinstance(real_node, ast.Num) and isinstance(real_node.n, float)
# Buggy code
def insert_existing_subtask(self, tid: str, line: int = None) -> None:
    """Insert an existing subtask in the buffer."""

    # Check if the task exists first
    if not self.req.has_task(tid):
        log.debug(f"Task {tid} not found")
        return

    if line is not None:
        start = self.buffer.get_iter_at_line(line)
    else:
        start = self.buffer.get_end_iter()
        self.buffer.insert(start, "\n")
        start.forward_line()
        line = start.get_line()

    # Add subtask name
    task = self.req.get_task(tid)
    self.buffer.insert(start, task.get_title())

    # Reset iterator
    start = self.buffer.get_iter_at_line(line)

    # Add checkbox
    self.add_checkbox(tid, start)

    # Apply link to subtask text
    end = start.copy()
    end.forward_to_line_end()

    link_tag = InternalLinkTag(tid, task.get_status())
    self.table.add(link_tag)
    self.buffer.apply_tag(link_tag, start, end)
    self.tags_applied.append(link_tag)

    # Apply subtask tag to everything
    start.backward_char()
    subtask_tag = SubTaskTag(tid)
    self.table.add(subtask_tag)
    self.buffer.apply_tag(subtask_tag, start, end)

    self.subtasks["tags"].append(tid)

    # Make sure subtasks can be deleted when removed in the text editor
    task.can_be_deleted = True


# Traceback (AttributeError)
2020-10-25 02:22:28,806 - ERROR - application:open_task:483 - Task 2376f725-ab76-4de9-b97a-489bf9bfb3d2 could not be found!
Traceback (most recent call last):
File "GTG/gtk/editor/text_tags.py", line 132, in on_tag
view.open_subtask_cb(self.tid)
File "GTG/gtk/editor/editor.py", line 709, in open_subtask
self.app.close_task(task.parents[0])
AttributeError: 'NoneType' object has no attribute 'parents'

# Fixed code
def insert_existing_subtask(self, tid: str, line: int = None) -> None:
    """Insert an existing subtask in the buffer."""

    # Check if the task exists first
    if not self.req.has_task(tid):
        log.debug(f"Task {tid} not found")
        return

    if line is not None:
        start = self.buffer.get_iter_at_line(line)
    else:
        start = self.buffer.get_end_iter()
        self.buffer.insert(start, "\n")
        start.forward_line()
        line = start.get_line()

    # Add subtask name
    task = self.req.get_task(tid)
    self.buffer.insert(start, task.get_title())

    # Reset iterator
    start = self.buffer.get_iter_at_line(line)

    # Add checkbox
    self.add_checkbox(tid, start)

    # Apply link to subtask text
    end = start.copy()
    end.forward_to_line_end()

    link_tag = InternalLinkTag(tid, task.get_status())
    self.table.add(link_tag)
    self.buffer.apply_tag(link_tag, start, end)
    self.tags_applied.append(link_tag)

    # Apply subtask tag to everything
    start.backward_char()
    subtask_tag = SubTaskTag(tid)
    self.table.add(subtask_tag)
    self.buffer.apply_tag(subtask_tag, start, end)

    self.subtasks["tags"].append(tid)
# Buggy code
def delete_editor_task(self, action, params):
    """Callback to delete the task currently open."""

    editor = self.get_active_editor()
    task = editor.task

    if task.is_new():
        self.close_task(task.get_id(), editor.window)
    else:
        self.delete_tasks([task.get_id()], editor.window)


# Traceback (TypeError)
Traceback (most recent call last):
File "GTG/gtk/application.py", line 292, in delete_editor_task
self.close_task(task.get_id(), editor.window)
TypeError: close_task() takes 2 positional arguments but 3 were given

# Fixed code
def delete_editor_task(self, action, params):
    """Callback to delete the task currently open."""

    editor = self.get_active_editor()
    task = editor.task

    if task.is_new():
        self.close_task(task.get_id())
    else:
        self.delete_tasks([task.get_id()], editor.window)
# Buggy code
def close_focused_task(self, action, params):
    """Callback to close currently focused task editor."""

    if self.open_tasks:
        tid = self.get_active_editor().task.get_id()
        self.close_task(tid)


# Traceback (AttributeError)
WARNING - application:close_task:467 - Tried to close tid d318eaed-03de-42dd-adfd-66a44bf2261c but it is not open

Traceback (most recent call last):
File "GTG/gtk/application.py", line 290, in close_focused_task
tid = self.get_active_editor().task.get_id()
AttributeError: 'NoneType' object has no attribute 'task'

WARNING - application:close_task:467 - Tried to close tid f53f937f-72a1-450a-b2ae-f4038a401ac3 but it is not open

# Fixed code
def close_focused_task(self, action, params):
    """Callback to close currently focused task editor."""

    editor = self.get_active_editor()

    if editor:
        self.close_task(editor.task.get_id())
# Buggy code
def close_task(self, tid):
    """Close a task editor window."""

    if tid in self.open_tasks:
        editor = self.open_tasks[tid]

        # We have to remove the tid first, otherwise
        # close_task would be called once again
        # by editor.close
        del self.open_tasks[tid]

        editor.close()

        open_tasks = self.config.get("opened_tasks")

        if tid in open_tasks:
            open_tasks.remove(tid)

        self.config.set("opened_tasks", open_tasks)

    else:
        log.warn(f"Tried to close tid {tid} but it is not open")


# Traceback (AttributeError)
WARNING - application:close_task:467 - Tried to close tid d318eaed-03de-42dd-adfd-66a44bf2261c but it is not open

Traceback (most recent call last):
File "GTG/gtk/application.py", line 290, in close_focused_task
tid = self.get_active_editor().task.get_id()
AttributeError: 'NoneType' object has no attribute 'task'

WARNING - application:close_task:467 - Tried to close tid f53f937f-72a1-450a-b2ae-f4038a401ac3 but it is not open

# Fixed code
def close_task(self, tid):
    """Close a task editor window."""

    try:
        editor = self.open_tasks[tid]
        editor.close()

        open_tasks = self.config.get("opened_tasks")

        if tid in open_tasks:
            open_tasks.remove(tid)

        self.config.set("opened_tasks", open_tasks)

    except KeyError:
        log.debug(f"Tried to close tid {tid} but it is not open")
# Buggy code
def destruction(self, a=None):
    # Save should be also called when buffer is modified
    self.pengine.onTaskClose(self.plugin_api)
    self.pengine.remove_api(self.plugin_api)
    tid = self.task.get_id()
    if self.task.is_new():
        self.req.delete_task(tid)
    else:
        self.save()
        for i in self.task.get_subtasks():
            if i:
                i.set_to_keep()
    self.app.close_task(tid)


# Traceback (AttributeError)
WARNING - application:close_task:467 - Tried to close tid d318eaed-03de-42dd-adfd-66a44bf2261c but it is not open

Traceback (most recent call last):
File "GTG/gtk/application.py", line 290, in close_focused_task
tid = self.get_active_editor().task.get_id()
AttributeError: 'NoneType' object has no attribute 'task'

WARNING - application:close_task:467 - Tried to close tid f53f937f-72a1-450a-b2ae-f4038a401ac3 but it is not open

# Fixed code
def destruction(self, _=None):
    """Callback when destroying the window."""

    # Save should be also called when buffer is modified
    self.pengine.onTaskClose(self.plugin_api)
    self.pengine.remove_api(self.plugin_api)

    tid = self.task.get_id()

    if self.task.is_new():
        self.req.delete_task(tid)
    else:
        self.save()
        [sub.set_to_keep() for sub in self.task.get_subtasks() if sub]

    try:
        del self.app.open_tasks[tid]
    except KeyError:
        log.debug(f"Task {tid} was already removed from the open list")
# Buggy code
def open_edit_backends(self, sender=None, backend_id=None):
    if not self.edit_backends_dialog:
        self.edit_backends_dialog = BackendsDialog(self.req)
        self.edit_backends_dialog.dialog.insert_action_group("app", self)

    self.edit_backends_dialog.activate()
    if backend_id is not None:
        self.edit_backends_dialog.show_config_for_backend(backend_id)


# Traceback (AttributeError)
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 110, in _builder_connect_callback
handler, args = _extract_handler_and_args(obj_or_map, handler_name)
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 90, in _extract_handler_and_args
raise AttributeError('Handler %s not found' % handler_name)
AttributeError: Handler on_BackendsDialog_delete_event not found
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 110, in _builder_connect_callback
handler, args = _extract_handler_and_args(obj_or_map, handler_name)
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 90, in _extract_handler_and_args
raise AttributeError('Handler %s not found' % handler_name)
AttributeError: Handler on_close_button_clicked not found

# Fixed code
def open_edit_backends(self, sender=None, backend_id=None):
    self.edit_backends_dialog = BackendsDialog(self.req)
    self.edit_backends_dialog.dialog.insert_action_group("app", self)

    self.edit_backends_dialog.activate()

    if backend_id:
        self.edit_backends_dialog.show_config_for_backend(backend_id)