1#Import librairies
2print("Loading Librairies ...")
3import pandas as pd
4import numpy as np 5from math import *
6
7from sklearn.ensemble import BaggingRegressor
2non-XML syntax that supports inline expressions and an optional
3sandboxed environment.
4"""
5from .bccache import BytecodeCache as BytecodeCache 6from .bccache import FileSystemBytecodeCache as FileSystemBytecodeCache
7from .bccache import MemcachedBytecodeCache as MemcachedBytecodeCache
8from .environment import Environment as Environment
27from .loaders import PrefixLoader as PrefixLoader
28from .runtime import ChainableUndefined as ChainableUndefined
29from .runtime import DebugUndefined as DebugUndefined
30from .runtime import make_logging_undefined as make_logging_undefined31from .runtime import StrictUndefined as StrictUndefined
32from .runtime import Undefined as Undefined
33from .utils import clear_caches as clear_caches
28from .runtime import ChainableUndefined as ChainableUndefined
29from .runtime import DebugUndefined as DebugUndefined
30from .runtime import make_logging_undefined as make_logging_undefined
31from .runtime import StrictUndefined as StrictUndefined32from .runtime import Undefined as Undefined
33from .utils import clear_caches as clear_caches
34from .utils import contextfunction
25from .loaders import ModuleLoader as ModuleLoader
26from .loaders import PackageLoader as PackageLoader
27from .loaders import PrefixLoader as PrefixLoader
28from .runtime import ChainableUndefined as ChainableUndefined29from .runtime import DebugUndefined as DebugUndefined
30from .runtime import make_logging_undefined as make_logging_undefined
31from .runtime import StrictUndefined as StrictUndefined
An object has been imported but is not used anywhere in the file. It should either be used or the import should be removed.
import os
def example():
print("This snippet is not using the `os` import anywhere.")
def example():
print("This looks good now!")
One major reason why this issue can cause confusion is when it's raised for imports that are meant to be exported, for use in other places.
For example, consider this file, mypackage/__init__.py
:
from mypackage.foo import is_foo
from mypackage.bar import bar_function
This is a very common pattern to export common functionality from modules, to
the top level of a package. But there is a major problem with this approach.
Consider this file, mypackage/foo.py
:
import os
def is_foo(item):
return os.path.exists(item)
Since os
is imported inside foo.py
, you can actually do this:
>>> from mypackage.foo import os
Although weird, Python automatically exports all imports in a file. In practice however, it is ill-advised to rely on this behaviour.
If you want to explicitly export an imported item in a file, add it to the
special variable named __all__
:
from mypackage.foo import is_foo
from mypackage.bar import bar_function
__all__ = ['is_foo', 'bar_function'] # Notice that these are strings!
DeepSource won't raise an issue if the imported item is present in __all__
.