when an exception is raised in python. it propagates up the call stack until it is processed on Odoo. the RPC layer that answers the calls made by the web client catches all exceptions and depending on the exception class, it will trigger different possible behaviors on web client.
An UserError will display error message in the user interface its define in odoo.exceptions class. The code of recipe changes the OSError to UserError to ensure the message is displayed in a friendly way. In all cases, the current database transaction is rolled back. In Odoo 9 and 10 use UserError to display error message.
Warning: in Odoo 8 openerp.exception.Warning played the role of UserError in 9 and 10 its deprecated because the name was deceptive (it is an error not warning) it collided with python built-in Warning class, it is kept for backward compatibility and you should use UserError in odoo 9 and 10.
in your case while we return a warning it means its only shows the warning message to user and transaction will not rollback.