Grid2op/grid2op

Wrong importation when importing a file named "utils.py" after grid2op

Closed this issue · 2 comments

Environment

  • Grid2op version: the behavior appears between1.9.6 and 1.9.8 and not before 1.9.5
  • System: windows and ubuntu16.04

Bug description

If you try to import from a file named utils.py after having imported grid2op, you don't import the functions in that utils.py file. You actually import the functions in grid2op.utils.

To get around the problem, a solution is of course to rename the utils.py file. We can also import utils before grid2op. This issue is not a priority, but it comprises some codes that were working with older versions of grid2op.

How to reproduce

Create a parent folder with three python scripts like this :

parent_folder /
- utils.py
- utils_v2.py
- script.py

The file utils.py contains the code:

def print_hello_world():
    print("Hello World")

The file utils_v2.py contains the code:

def print_hello_world_v2():
    print("Hello World v2")

The file script.py contains the code:

import grid2op
from utils import *
from utils_v2 import *

print(dir(utils))
print(dir(utils_v2))

Run the script.py file.

Current output with a version >= 1.9.6

['EpisodeStatistics', 'ScoreICAPS2021', 'ScoreL2RPN2020', 'ScoreL2RPN2022', 'ScoreL2RPN2023', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'print_hello_world_v2'] 

Expected output

['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'print_hello_world'] 
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'print_hello_world_v2'] 

Solved in 1.9.8 released :-)

It works for me now, thanks :)