77from pathlib import Path
88from select import select
99
10- from traitlets import Dict
10+ from traitlets import Dict as tDict
1111from metakernel import MetaKernel , ExceptionWrapper
1212# from IPython.display import Image, SVG
1313
1414from tabulate import tabulate
1515import psycopg2
1616from psycopg2 import Error , OperationalError
1717from psycopg2 .extensions import (
18- QueryCanceledError , POLL_OK , POLL_READ , POLL_WRITE , STATUS_BEGIN , Union
18+ QueryCanceledError , POLL_OK , POLL_READ , POLL_WRITE , STATUS_BEGIN
1919)
20- from typing import Any , List , Optional , TypedDict , Iterable , Sequence , Mapping , Union , Tuple
20+ from typing import Any , List , Optional , TypedDict , Iterable , Sequence , Mapping , Union , Tuple , Dict
2121from . import __version__
2222
2323KernelDictType = TypedDict (
@@ -79,7 +79,7 @@ def get_kernel_json() -> KernelDictType:
7979 return data
8080
8181
82- def wait_select_inter (conn : psycopg2 .connection ) -> None :
82+ def wait_select_inter (conn : " psycopg2.connection" ) -> None :
8383 """等待连接建立.
8484
8585 Args:
@@ -111,7 +111,7 @@ class MissingConnection(Exception):
111111
112112
113113class RowsDisplay :
114- def __init__ (self , header : Union [str , Mapping [str , str ], Sequence [str ]], rows : Union [Mapping [str , Iterable ], Iterable [Iterable ]]) -> None :
114+ def __init__ (self , header : Union [str , Dict [str , str ], Sequence [str ]], rows : Union [Mapping [str , Iterable ], Iterable [Iterable ]]) -> None :
115115 self .header = header
116116 self .rows = rows
117117
@@ -132,13 +132,13 @@ class PostgreSQLKernel(MetaKernel):
132132 implementation_version : str = __version__
133133 language : str = 'sql'
134134 help_links : List [HelpLinkDictType ] = HELP_LINKS
135- kernel_json : Dict = Dict (get_kernel_json ()).tag (config = True )
135+ kernel_json : tDict = tDict (get_kernel_json ()).tag (config = True )
136136 _language_version : Optional [str ] = None
137137 _banner : Optional [str ] = None
138138
139139 _conn_string : str
140140 _autocommit : bool
141- _conn : Optional [psycopg2 .connection ]
141+ _conn : Optional [" psycopg2.connection" ]
142142
143143 @property
144144 def language_version (self ) -> str :
@@ -160,7 +160,7 @@ def banner(self) -> Optional[str]:
160160 if self ._conn is None :
161161 return 'not yet connected to a database'
162162 res = self .fetchone ('SELECT VERSION();' )
163- if res and len (res ) >= 1 :
163+ if res and len (res ) >= 1 and isinstance ( res [ 0 ], str ) :
164164 self ._banner = res [0 ]
165165 return self ._banner
166166
0 commit comments