Skip to content

papis-scihub attribute error #64

Description

@nukhes

Downloader.__init__ in papis_scihub/plugin.py calls self.logger.warning(...) before the parent papis.downloaders.Downloader.__init__. since self.logger and self.session are both set up by the parent's __init__, this crashes with an AttributeError.

Reproduce

papis add --from scihub https://doi.org/10.1080/17499518.2025.2581567

Traceback

Traceback (most recent call last):
  File ".../papis/importer/__init__.py", line 216, in match
    importer = cls.match(uri)
  File ".../papis_scihub/plugin.py", line 54, in match
    return Downloader(url)
  File ".../papis_scihub/plugin.py", line 37, in __init__
    self.logger.warning(WARNING_NOTICE)
    ^^^^^^^^^^^
AttributeError: 'Downloader' object has no attribute 'logger'

Cause

in plugin.py, the parent __init__ is called after self.logger is used:

class Downloader(papis.downloaders.Downloader):
    def __init__(self, uri: str) -> None:
        self.logger.warning(WARNING_NOTICE)
        papis.downloaders.Downloader.__init__(self, uri=uri, name="sci-hub") 

self.logger and self.session are both initialised inside papis.downloaders.Downloader.__init__, so they don't exist when line 37 runs.

Suggested fix

 class Downloader(papis.downloaders.Downloader):
     def __init__(self, uri: str) -> None:
-        self.logger.warning(WARNING_NOTICE)
         papis.downloaders.Downloader.__init__(self, uri=uri, name="sci-hub")
+        self.logger.warning(WARNING_NOTICE)

My Env

  • papis: 0.15.0
  • papis-scihub: 0.1.3 (commit 4a7b88b)
  • Python: 3.13

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions