How fix PyYAML load() got an unexpected keyword argument 'loader

Problem

You are trying to use a specific YAML loader with PyYAML using code such as

import yaml
from yaml import CSafeLoader

#...
data = yaml.load(f, loader=CSafeLoader)

but you see an error like this:

  File "/usr/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/uli/.local/lib/python3.12/site-packages/pydantic/validate_call_decorator.py", line 60, in wrapper_function
    return validate_call_wrapper(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/uli/.local/lib/python3.12/site-packages/pydantic/_internal/_validate_call.py", line 96, in __call__
    res = self.__pydantic_validator__.validate_python(pydantic_core.ArgsKwargs(args, kwargs))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/uli/dev/SpiroFit/PlotServer/SpiroFit/SpiroFitDataManager.py", line 288, in read_measurement
    data = yaml.load(decoded_data, loader=CSafeLoader)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: load() got an unexpected keyword argument 'loader'

Solution

The solution here is simple. The loader argument needs to be spelled with a captial L:

data = yaml.load(f, Loader=CSafeLoader)