Home > Mobile >  What does / mean as a python argument?
What does / mean as a python argument?

Time:05-18

    def assert_called_with(self, /, *args, **kwargs):
        """assert that the last call was made with the specified arguments.

        Raises an AssertionError if the args and keyword args passed in are
        different to the last call to the mock."""
        if self.call_args is None:
            expected = self._format_mock_call_signature(args, kwargs)
            actual = 'not called.'
            error_message = ('expected call not found.\nExpected: %s\nActual: %s'
                    % (expected, actual))
            raise AssertionError(error_message)

I've never come across / in the arguments of a python function before and it doesn't appear to be used here (in mock.py of the mock library). So what does it do?

CodePudding user response:

This is used to idicate that anything before the / is a positional only parameter. Note that a function like range which has start, stop, and step does not allow keyword arguments, eg you cannot do range(stop = 3) for example. That is because of the use of / in the function definition. Check here for further elaboration

  • Related