This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TL;DR: use isinstance for subclass-friendly type checks unless microperf is needed, then use type is or type in (set) as needed | |
Timings on 3.11-3.13 | |
3.11: | |
wrong: 0.01907933602342382s | |
isinstance: 0.03639550699153915s | |
isinstance (multiple types tuple): 0.0790955779957585s | |
in set: 0.05437163001624867s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import importlib | |
import os | |
import pkgutil | |
import sys | |
from pathlib import Path | |
# note these are the loader attribute prefix names from loader.py, we convert them later to the collection loader plugin type values | |
PLUGIN_TYPES = ['module', 'become', 'cache', 'callback', 'connection', 'shell', 'inventory'] | |