Skip to content

Commit

Permalink
Merge pull request #3248 from bdarnell/auto-import
Browse files Browse the repository at this point in the history
typing: Eagerly import all submodules in __init__.pyi
  • Loading branch information
bdarnell committed Apr 8, 2023
2 parents d369a78 + 7c842b4 commit 86c9151
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
4 changes: 1 addition & 3 deletions docs/releases/v6.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ General changes
version 3.11.1.
- Tornado submodules are now imported automatically on demand. This means it is
now possible to use a single ``import tornado`` statement and refer to objects
in submodules such as `tornado.web.RequestHandler`. Note that this automatic
import is not currently compatible with type checkers such as mypy, so users
of these tools may still wish to import the submodules explicitly.
in submodules such as `tornado.web.RequestHandler`.

Deprecation notices
~~~~~~~~~~~~~~~~~~~
Expand Down
33 changes: 33 additions & 0 deletions tornado/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import typing

version: str
version_info: typing.Tuple[int, int, int, int]

from . import auth
from . import autoreload
from . import concurrent
from . import curl_httpclient
from . import escape
from . import gen
from . import http1connection
from . import httpclient
from . import httpserver
from . import httputil
from . import ioloop
from . import iostream
from . import locale
from . import locks
from . import log
from . import netutil
from . import options
from . import platform
from . import process
from . import queues
from . import routing
from . import simple_httpclient
from . import tcpclient
from . import tcpserver
from . import template
from . import testing
from . import util
from . import web
4 changes: 1 addition & 3 deletions tornado/test/import_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ def test_lazy_import(self):

def test_import_aliases(self):
# Ensure we don't delete formerly-documented aliases accidentally.
import tornado.ioloop
import tornado.gen
import tornado.util
import tornado
import asyncio

self.assertIs(tornado.ioloop.TimeoutError, tornado.util.TimeoutError)
Expand Down
2 changes: 0 additions & 2 deletions tornado/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,8 @@ async def main():
from tornado.httpserver import HTTPServer
from tornado import httputil
from tornado import iostream
import tornado.locale
from tornado import locale
from tornado.log import access_log, app_log, gen_log
import tornado.netutil
from tornado import template
from tornado.escape import utf8, _unicode
from tornado.routing import (
Expand Down
2 changes: 1 addition & 1 deletion tornado/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import os
import sys
import struct
import tornado.web
import tornado
from urllib.parse import urlparse
import zlib

Expand Down

0 comments on commit 86c9151

Please sign in to comment.