Skip to content

A short and sweet command line utility to find all names that have been imported with a universal (AKA wildcard) import and replace them with less dangerous import structures.

master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 

README.md

About

A short and sweet command line utility to find all names that have been imported with a universal (AKA wildcard) import and replace them with less dangerous import structures.

Turn this:

from numpy import *
    
x = array([1])

into this:

import numpy
x = numpy.array([1])

Motivation

Hopefully, this tool can help mitigate some of the pain involved in identifying what's what and cleaning up code a little.

Usage

usage: universal-fixer.py [-h] [--replace] file_path

Find all function names from universal imports and fix them!

positional arguments:
  file_path   Python file to find and replace universal imports in

optional arguments:
  -h, --help  show this help message and exit
  --replace   Indicate you want to replace found matches to conform to PEP8 standard for wildcard import. 
              Omitted, universal-fixer only searches and displays found matches, but does not alter the actual file.

Example output for python universal-fixer.py test.py:

Found expression `abstractmethod` that belongs to module namespace `abc` in following contexts:
	Line 11: ...@abstractmethod
Found expression `ABCMeta` that belongs to module namespace `abc` in following contexts:
	Line 9: ...re.replacegoobersmakr; x = ABCMeta([1]); wefzsegsergaewfsefsefsdfgs...
Found expression `array` that belongs to module namespace `numpy` in following contexts:
	Line 12: ...+array(10)-array(5)+(array(14) / array(19))...
Found expression `testing` that belongs to module namespace `numpy` in following contexts:
	Line 2: ...A demo file for testing. ...

With --replace, expect to be prompted before changing each import.

About

A short and sweet command line utility to find all names that have been imported with a universal (AKA wildcard) import and replace them with less dangerous import structures.

Topics

Resources

Releases

No releases published

Packages

No packages published

Languages