Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Module import fails if a directory exists with same name #7229

@peterhinch

Description

@peterhinch

Tested under Unix and RP2.

To replicate create a directory (e.g. ~/test) containing foo.py:

def bar():
    print('bar')

Import behaves as expected. CPython behaves identically.:

MicroPython v1.14 on 2021-03-28; Raspberry Pi Pico with RP2040
Type "help()" for more information.
>>> import foo
>>> dir(foo)
['__class__', '__name__', '__file__', 'bar']
>>> 

Create a subdirectory foo and repeat:

MicroPython v1.14 on 2021-03-28; Raspberry Pi Pico with RP2040
Type "help()" for more information.
>>> import foo
>>> dir(foo)
['__class__', '__name__', '__path__']

CPython correctly imports the module:

[adminpete@capybara]: ~/test
$ python3
Python 3.8.5 (default, Jan 27 2021, 15:41:15) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import foo
>>> dir(foo)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'bar']
>>> 

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