Issue 3314. The sys module is used in an error case.
diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py
index 8edc963..fe02db5 100644
--- a/Lib/urllib/parse.py
+++ b/Lib/urllib/parse.py
@@ -4,6 +4,8 @@
 UC Irvine, June 1995.
 """
 
+import sys
+
 __all__ = ["urlparse", "urlunparse", "urljoin", "urldefrag",
            "urlsplit", "urlunsplit"]
 
@@ -599,7 +601,6 @@
 """
 
 def test():
-    import sys
     base = ''
     if sys.argv[1:]:
         fn = sys.argv[1]