1515 MethodSigContext ,
1616 Plugin ,
1717)
18- from mypy .plugins import singledispatch_const
18+ from mypy .plugins import constants
1919from mypy .plugins .common import try_getting_str_literals
2020from mypy .subtypes import is_subtype
2121from mypy .typeops import is_literal_type_like , make_simplified_union
@@ -52,31 +52,39 @@ class DefaultPlugin(Plugin):
5252 """Type checker plugin that is enabled by default."""
5353
5454 def get_function_hook (self , fullname : str ) -> Callable [[FunctionContext ], Type ] | None :
55- from mypy .plugins import ctypes , enums , singledispatch
56-
5755 if fullname == "_ctypes.Array" :
56+ from mypy .plugins import ctypes
57+
5858 return ctypes .array_constructor_callback
5959 elif fullname == "functools.singledispatch" :
60+ from mypy .plugins import singledispatch
61+
6062 return singledispatch .create_singledispatch_function_callback
6163 elif fullname == "functools.partial" :
6264 import mypy .plugins .functools
6365
6466 return mypy .plugins .functools .partial_new_callback
6567 elif fullname == "enum.member" :
68+ from mypy .plugins import enums
69+
6670 return enums .enum_member_callback
6771
6872 return None
6973
7074 def get_function_signature_hook (
7175 self , fullname : str
7276 ) -> Callable [[FunctionSigContext ], FunctionLike ] | None :
73- from mypy .plugins import attrs , dataclasses
74-
7577 if fullname in ("attr.evolve" , "attrs.evolve" , "attr.assoc" , "attrs.assoc" ):
78+ from mypy .plugins import attrs
79+
7680 return attrs .evolve_function_sig_callback
7781 elif fullname in ("attr.fields" , "attrs.fields" ):
82+ from mypy .plugins import attrs
83+
7884 return attrs .fields_function_sig_callback
7985 elif fullname == "dataclasses.replace" :
86+ from mypy .plugins import dataclasses
87+
8088 return dataclasses .replace_function_sig_callback
8189 return None
8290
@@ -93,7 +101,7 @@ def get_method_signature_hook(
93101 from mypy .plugins import ctypes
94102
95103 return ctypes .array_setitem_callback
96- elif fullname == singledispatch_const .SINGLEDISPATCH_CALLABLE_CALL_METHOD :
104+ elif fullname == constants .SINGLEDISPATCH_CALLABLE_CALL_METHOD :
97105 from mypy .plugins import singledispatch
98106
99107 return singledispatch .call_singledispatch_function_callback
@@ -126,11 +134,11 @@ def get_method_hook(self, fullname: str) -> Callable[[MethodContext], Type] | No
126134 from mypy .plugins import ctypes
127135
128136 return ctypes .array_iter_callback
129- elif fullname == singledispatch_const .SINGLEDISPATCH_REGISTER_METHOD :
137+ elif fullname == constants .SINGLEDISPATCH_REGISTER_METHOD :
130138 from mypy .plugins import singledispatch
131139
132140 return singledispatch .singledispatch_register_callback
133- elif fullname == singledispatch_const . REGISTER_CALLABLE_CALL_METHOD :
141+ elif fullname == constants . SINGLEDISPATCH_REGISTER_CALLABLE_CALL_METHOD :
134142 from mypy .plugins import singledispatch
135143
136144 return singledispatch .call_singledispatch_function_after_register_argument
@@ -141,15 +149,21 @@ def get_method_hook(self, fullname: str) -> Callable[[MethodContext], Type] | No
141149 return None
142150
143151 def get_attribute_hook (self , fullname : str ) -> Callable [[AttributeContext ], Type ] | None :
144- from mypy .plugins import ctypes , enums
145-
146152 if fullname == "_ctypes.Array.value" :
153+ from mypy .plugins import ctypes
154+
147155 return ctypes .array_value_callback
148156 elif fullname == "_ctypes.Array.raw" :
157+ from mypy .plugins import ctypes
158+
149159 return ctypes .array_raw_callback
150- elif fullname in enums .ENUM_NAME_ACCESS :
160+ elif fullname in constants .ENUM_NAME_ACCESS :
161+ from mypy .plugins import enums
162+
151163 return enums .enum_name_callback
152- elif fullname in enums .ENUM_VALUE_ACCESS :
164+ elif fullname in constants .ENUM_VALUE_ACCESS :
165+ from mypy .plugins import enums
166+
153167 return enums .enum_value_callback
154168 return None
155169
0 commit comments