MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _auto_fn

Function _auto_fn

lib/sqlalchemy/dialects/__init__.py:24–57  ·  view source on GitHub ↗

default dialect importer. plugs into the :class:`.PluginLoader` as a first-hit system.

(name: str)

Source from the content-addressed store, hash-verified

22
23
24def _auto_fn(name: str) -> Optional[Callable[[], Type[Dialect]]]:
25 """default dialect importer.
26
27 plugs into the :class:`.PluginLoader`
28 as a first-hit system.
29
30 """
31 if "." in name:
32 dialect, driver = name.split(".")
33 else:
34 dialect = name
35 driver = "base"
36
37 try:
38 if dialect == "mariadb":
39 # it's "OK" for us to hardcode here since _auto_fn is already
40 # hardcoded. if mysql / mariadb etc were third party dialects
41 # they would just publish all the entrypoints, which would actually
42 # look much nicer.
43 module: Any = __import__(
44 "sqlalchemy.dialects.mysql.mariadb"
45 ).dialects.mysql.mariadb
46 return module.loader(driver) # type: ignore
47 else:
48 module = __import__("sqlalchemy.dialects.%s" % (dialect,)).dialects
49 module = getattr(module, dialect)
50 except ImportError:
51 return None
52
53 if hasattr(module, driver):
54 module = getattr(module, driver)
55 return lambda: module.dialect
56 else:
57 return None
58
59
60registry = util.PluginLoader("sqlalchemy.dialects", auto_fn=_auto_fn)

Callers

nothing calls this directly

Calls 2

splitMethod · 0.80
loaderMethod · 0.45

Tested by

no test coverage detected