Skip to content

importhook.cs breaks python's import interface #1245

@SStarosielec

Description

@SStarosielec

Environment

  • Pythonnet version: 2.5.1
  • Python version: 3.7.9
  • Operating System: Windows 10

Details

  • Describe what you were trying to get done.

pythonnet overwrites the python's __import__ routine, but does not implement python's signature precisely:
original python's signature is

__import__(name, globals=None, locals=None, fromlist=(), level=0)

Most other python modules call the name parameter as positional: __import__("foo", ...

Some packages (e.g. kivy) use __import__ as

    __import__(
        name='{2}.{0}.{1}'.format(basemodule, modulename, base),
        globals=globals(), locals=locals(), fromlist=[modulename], level=0
    )

i.e. the name argument used as keyword argument in the call. Both calls are valid in python's __import__, but fail at the overwritten __import__ with

TypeError: __import__() takes at least 1 argument (0 given)

A hotfix is to alter the other modules code to

    __import__(
        '{2}.{0}.{1}'.format(basemodule, modulename, base),
        globals=globals(), locals=locals(), fromlist=[modulename], level=0
    )

but the broken code is within pythonnet.

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy