mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	Speed up YAML by using YAML C loader when available (#5721)
This commit is contained in:
		| @@ -23,6 +23,14 @@ from esphome.core import ( | |||||||
| from esphome.helpers import add_class_to_obj | from esphome.helpers import add_class_to_obj | ||||||
| from esphome.util import OrderedDict, filter_yaml_files | from esphome.util import OrderedDict, filter_yaml_files | ||||||
|  |  | ||||||
|  | try: | ||||||
|  |     from yaml import CSafeLoader as FastestAvailableSafeLoader | ||||||
|  | except ImportError: | ||||||
|  |     from yaml import (  # type: ignore[assignment] | ||||||
|  |         SafeLoader as FastestAvailableSafeLoader, | ||||||
|  |     ) | ||||||
|  |  | ||||||
|  |  | ||||||
| _LOGGER = logging.getLogger(__name__) | _LOGGER = logging.getLogger(__name__) | ||||||
|  |  | ||||||
| # Mostly copied from Home Assistant because that code works fine and | # Mostly copied from Home Assistant because that code works fine and | ||||||
| @@ -89,7 +97,7 @@ def _add_data_ref(fn): | |||||||
|     return wrapped |     return wrapped | ||||||
|  |  | ||||||
|  |  | ||||||
| class ESPHomeLoader(yaml.SafeLoader): | class ESPHomeLoader(FastestAvailableSafeLoader): | ||||||
|     """Loader class that keeps track of line numbers.""" |     """Loader class that keeps track of line numbers.""" | ||||||
|  |  | ||||||
|     @_add_data_ref |     @_add_data_ref | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user