This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: self in classes missinterpreted as a string.
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.7, Python 3.6
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Decorater
Priority: normal Keywords:

Created on 2017-01-12 12:27 by Decorater, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg285316 - (view) Author: Decorater (Decorater) * Date: 2017-01-12 12:27
So, I have a class (it subclasses the zipimporter for my import hook) that allows me to not worry about issues when the hook is appended to the beginning of the path hooks.

The code to the class as follows:

class OriginalZipImport(zipimport.zipimporter):
    Original zipimporter class. Modified for requirements of this import hook.
    # Sadly I have to manually specify the file extensions the original
    # zipimporter supports to bypass an AttributeError.
    # according to
    # zipimport only allows importing ``.py`` and ``.pyc`` files from zips.
    extensions = ['.py', '.pyc']

    def __init__(self, archivepath):
        super(OriginalZipImport, self.inst).__init__(self, archivepath)

    def find_loader(self, fullname, path=None):
        Original find_loader.
        self.inst.find_loader(fullname, path=path)

    def find_module(self, fullname, path=None):
        Original find_module.
        self.inst.find_module(self, fullname, path=path)

    def load_module(self, fullname):
        Original load_module.
        self.inst.load_module(self, fullname)

However instead of working like the way I would expect it gives this traceback:

Traceback (most recent call last):
  File "E:\Users\Elsword\Desktop\DecoraterBot\Async\\zipmaker\", line 11, in <module>
    from pathlib import Path
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 946, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 885, in _find_spec
  File "<frozen importlib._bootstrap_external>", line 1157, in find_spec
  File "<frozen importlib._bootstrap_external>", line 1129, in _get_spec
  File "<frozen importlib._bootstrap_external>", line 1273, in find_spec
  File "<frozen importlib._bootstrap_external>", line 1229, in _get_spec
  File "E:\Users\Elsword\Desktop\DecoraterBot\Async\zipmaker\py2pycx\", line 180, in find_loader
    self.inst.find_loader(fullname, path=path)
AttributeError: 'str' object has no attribute 'inst'

Note: it does use a slightly modified that is different than the one that is on the python source trees. It is specifically for testing the hook to see if it works or not.

The hook is supposed to work however it is confusing why it is doing this as I did not set self to be an string so it should allow me to do all of this just fine.
msg285347 - (view) Author: Decorater (Decorater) * Date: 2017-01-12 20:39
Also I sadly have to make this a dummy class just to add in an actual dictionary with the file extensions it supports because I cant use setattr on it. It is retarded that you cant use it for builtin types or classes if your code actually requires such.
msg285348 - (view) Author: Decorater (Decorater) * Date: 2017-01-12 20:41
Also in the code I had to subclass it 3 times, 1 time to preserver original functionality as if the hook was not inserted in the front of the path hooks, another time for 1 format of files it should be able to allow importing of, and the other time for another format of files.
Date User Action Args
2022-04-11 14:58:41adminsetgithub: 73438
2017-05-17 17:31:46Decoratersetstatus: open -> closed
resolution: not a bug
stage: resolved
2017-01-12 20:41:15Decoratersetmessages: + msg285348
2017-01-12 20:39:48Decoratersetmessages: + msg285347
2017-01-12 12:27:27Decoratercreate