8000 Change import statements to import only what's needed by denisra · Pull Request #468 · python/asyncio · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

Change import statements to import only what's needed #468

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Changed the import statements so they are sorted alphabetically
  • Loading branch information
denisra committed Nov 18, 2016
commit b92866fd652caa95de7de7c30b5e89007998fef4
5 changes: 2 additions & 3 deletions examples/cacheclt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
"""

import argparse
import json
import logging

import asyncio
import asyncio.test_utils
import json
import logging

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imports should be sorted alphabetically (that's what we try to do in asyncio and CPython code bases).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@1st1 I wasn't aware of that, sorry. I was going by the PEP8 guidelines, where it tells us to import the standard library modules first. But I'll have that fix following your recommendations.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@denisra Asyncio is technically a stdlib module. ;)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SethMichaelLarson I can't say that it isn't :) will send send in another commit in just a few min with that fixed


ARGS = argparse.ArgumentParser(description='Cache client example.')
Expand Down
4 changes: 1 addition & 3 deletions examples/cachesvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,12 @@
"""

import argparse
import asyncio
import json
import logging
import os
import random

import asyncio


ARGS = argparse.ArgumentParser(description='Cache server example.')
ARGS.add_argument(
'--tls', action='store_true', dest='tls',
Expand Down
9 changes: 4 additions & 5 deletions examples/crawl.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
# - Handle out of file descriptors directly? (How?)

import argparse
import asyncio
import asyncio.locks
import cgi
from http.client import BadStatusLine
import logging
import re
import sys
import time
import urllib.parse
import cgi
from http.client import BadStatusLine

import asyncio
import asyncio.locks


ARGS = argparse.ArgumentParser(description="Web crawler")
Expand Down
3 changes: 1 addition & 2 deletions examples/fetch0.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""Simplest possible HTTP client."""

import sys

import asyncio
import sys


@asyncio.coroutine
Expand Down
3 changes: 1 addition & 2 deletions examples/fetch1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
This version adds URL parsing (including SSL) and a Response object.
"""

import asyncio
import sys
import urllib.parse

import asyncio


class Response:

Expand Down
5 changes: 2 additions & 3 deletions examples/fetch2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
This version adds a Request object.
"""

import asyncio
from http.client import BadStatusLine
import sys
import urllib.parse
from http.client import BadStatusLine

import asyncio


class Request:
Expand Down
5 changes: 2 additions & 3 deletions examples/fetch3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
chunked transfer-encoding. It also supports a --iocp flag.
"""

import asyncio
from http.client import BadStatusLine
import sys
import urllib.parse
from http.client import BadStatusLine

import asyncio


class ConnectionPool:
Expand Down
3 changes: 1 addition & 2 deletions examples/fuzz_as_completed.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

"""Fuzz tester for as_completed(), by Glenn Langford."""

import asyncio
import itertools
import random
import sys

import asyncio


@asyncio.coroutine
def sleeper(time):
Expand Down
3 changes: 1 addition & 2 deletions examples/qspeed.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/usr/bin/env python3
"""How fast is the queue implementation?"""

import time

import asyncio
import time


print(asyncio)
Expand Down
3 changes: 1 addition & 2 deletions examples/shell.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""Examples using create_subprocess_exec() and create_subprocess_shell()."""


import signal

import asyncio
from asyncio.subprocess import PIPE
import signal


@asyncio.coroutine
Expand Down
3 changes: 1 addition & 2 deletions examples/simple_tcp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
fail if this port is currently in use.
"""

import sys

import asyncio
import asyncio.streams
import sys


class MyServer:
Expand Down
3 changes: 1 addition & 2 deletions examples/sink.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""Test service that accepts connections and reads all data off them."""

import argparse
import asyncio
import os
import sys

import asyncio


ARGS = argparse.ArgumentParser(description="TCP data sink example.")
ARGS.add_argument(
Expand Down
3 changes: 1 addition & 2 deletions examples/source.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""Test client that connects and sends infinite data."""

import argparse
import sys

import asyncio
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also import asyncio.test_utils.

import asyncio.test_utils
import sys


ARGS = argparse.ArgumentParser(description="TCP data sink example.")
Expand Down
3 changes: 1 addition & 2 deletions examples/source1.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""Like source.py, but uses streams."""

import argparse
import sys

import asyncio
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asyncio.test_utils

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why we use test_utils anyways. It should be removed from examples.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brettcannon Thanks for pointing that out. I made the changes as suggested. Please let me know if I need to change anything else.

import asyncio.test_utils
import sys


ARGS = argparse.ArgumentParser(description="TCP data sink example.")
Expand Down
2 changes: 1 addition & 1 deletion examples/subprocess_attach_read_pipe.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env python3
"""Example showing how to attach a read pipe to a subprocess."""

import asyncio
import os
import sys

import asyncio

code = """
import os, sys
Expand Down
4 changes: 2 additions & 2 deletions examples/subprocess_attach_write_pipe.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env python3
"""Example showing how to attach a write pipe to a subprocess."""

import asyncio
from asyncio.subprocess import PIPE
import os
import sys

import asyncio
from asyncio.subprocess import PIPE

code = """
import os, sys
Expand Down
3 changes: 1 addition & 2 deletions examples/subprocess_shell.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""Example writing to and reading from a subprocess at the same time using
tasks."""

import os

import asyncio
from asyncio.subprocess import PIPE
import os


@asyncio.coroutine
Expand Down
3 changes: 1 addition & 2 deletions examples/tcp_echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
"""TCP echo server example."""

import argparse
import sys

import asyncio
import sys


try:
Expand Down
7 changes: 3 additions & 4 deletions examples/timing_tcp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
fail if this port is currently in use.
"""

import sys
import time
import random

import asyncio
import asyncio.streams
import random
import sys
import time


class MyServer:
Expand Down
3 changes: 1 addition & 2 deletions examples/udp_echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
"""UDP echo example."""

import argparse
import sys

import asyncio
import sys


try:
Expand Down
0