Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing IOUtilities unintentionally causes a warnings.simplefilter("all") globally. #249

Open
godot11 opened this issue Sep 30, 2022 · 0 comments

Comments

@godot11
Copy link

godot11 commented Sep 30, 2022

In SimEx.Utilities.IOUtilities, there's an import

from wpg.converters.genesis_v2 import read_genesis_file as genesis2

that silently causes ALL warnings ever, globally, to be supressed after this line. Probably there's a warnings.simplefilter("ignore") line in WPG somewhere. In fact, it's more severe: anything that imports wpg or (probably) any part of it is affected.

This sounds like a serious unintended side effect. It will happen to anything that imports SimEx.Utilities.IOUtilities, and anything that imports the code that imports it, and so on.

If WPG is not under our control, a possible fix would be to add warnings.simplefilter("ignore") after every place in SimEx WPG is imported. This may also cause troubles however, as it also overrides any intentional warnings filter applied beforehand.

MRE of bug and fix:

import warnings
warnings.warn("First warning before import")

import wpg
# from wpg.converters.genesis_v2 import read_genesis_file as genesis2  # causes the same behaviour
# from SimEx.Utilities.IOUtilities import loadPDB  # causes the same behaviour

warnings.warn("Second warning after import")

warnings.simplefilter("default")
warnings.warn("Third warning after filter reset")

This will print

pdb_wtf.py:2: UserWarning: First warning before import
  warnings.warn("First warning before import")
initializing ocelot...
pdb_wtf.py:9: UserWarning: Third warning after filter reset
  warnings.warn("Third warning after filter reset")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant