title: Python - 2 arguments instead of one?
body: <p>Python Code:</p>
  <pre class="lang-py prettyprint-override"><code>class Importer:
      from importlib import __import__, reload
      from sys import modules
  
      libname = &quot;&quot;
      import_count = 0
      module = None
  
      def __init__(self, name):
          self.libname = name
          self.import_count = 0
  
      def importm(self):
          if self.libname not in self.modules:
              self.module = __import__(self.libname)
          else:
              print(&quot;must reload&quot;)
              self.module = self.reload(self.module)
          self.import_count += 1
  
  # test out Importer
  
  importer = Importer(&quot;module&quot;)
  
  importer.importm() # prints Hello
  importer.importm() # prints Hello
  importer.importm() # prints Hello (again)
  print(importer.import_count)
  </code></pre>
  <p>The above Python (3.8.1) code is at <a href="https://www.onlinegdb.com/fork/SkCBRtf2w" rel="nofollow noreferrer">OnlineGDB</a>, which if you run, will give an error:</p>
  <pre class="lang-none prettyprint-override"><code>TypeError: reload() takes 1 positional argument but 2 were given
  </code></pre>
  <p>When I open up the <code>importlib</code> library in Python, I see this:</p>
  <pre class="lang-py prettyprint-override"><code>
  # ... (previous code; unnecessary)
  
  _RELOADING = {}
  
  
  def reload(module): ## this is where reload is defined (one argument)
      &quot;&quot;&quot;Reload the module and return it.
  
      The module must have been successfully imported before.
  
      &quot;&quot;&quot;
      if not module or not isinstance(module, types.ModuleType): ## check for type of module
          raise TypeError(&quot;reload() argument must be a module&quot;)
      try:
          name = module.__spec__.name
      except AttributeError:
          name = module.__name__
  
      if sys.modules.get(name) is not module: ## other code you (probably) don't have to care about
          msg = &quot;module {} not in sys.modules&quot;
          raise ImportError(msg.format(name), name=name)
      if name in _RELOADING:
          return _RELOADING[name]
      _RELOADING[name] = module
      try:
          parent_name = name.rpartition('.')[0]
          if parent_name:
              try:
                  parent = sys.modules[parent_name]
              except KeyError:
                  msg = &quot;parent {!r} not in sys.modules&quot;
                  raise ImportError(msg.format(parent_name),
                                    name=parent_name) from None
              else:
                  pkgpath = parent.__path__
          else:
              pkgpath = None
          target = module
          spec = module.__spec__ = _bootstrap._find_spec(name, pkgpath, target)
          if spec is None:
              raise ModuleNotFoundError(f&quot;spec not found for the module {name!r}&quot;, name=name)
          _bootstrap._exec(spec, module)
          # The module may have replaced itself in sys.modules!
          return sys.modules[name]
      finally:
          try:
              del _RELOADING[name]
          except KeyError:
              pass
  
  # ... (After code; unnecessary)
  
  </code></pre>
  <p><strong>All double hashtag (##) comments are mine</strong></p>
  <p>It is clearly visible that <code>reload</code> DOES have 1 argument, and it checks if that argument is a module.  In <a href="https://www.onlinegdb.com/fork/SkCBRtf2w" rel="nofollow noreferrer">the OGDB (OnineGDB) code</a>, I am only passing one argument (pretty sure) and it is of type module (most likely).  If I remove that argument (you can edit the OGDB), it gives:</p>
  <pre class="lang-none prettyprint-override"><code>TypeError: reload() argument must be module
  </code></pre>
  <p>So for some reason, Python keeps thinking I have one more argument than I do actually have.  The only way I made it work was editing the <code>importlib</code> file to have <code>reload</code> have two arguments (not a good idea).</p>
  <p>I tried running PDB, not helpful.</p>
  <p>Can anyone spot anything obviously wrong, like actually having two arguments?</p>