== Why is this an issue?

An assert is inappropriate for parameter validation because assertions are disabled globally at the interpreter level when the application runs as optimize bytecode (-O and -OO command line switches). It means that the optimize version of the application would completely eliminate the intended checks.


This rule raises an issue when a ``++public++`` method uses one or more of its parameters with ``++assert++``s.

=== Noncompliant code example

[source,python]
----
class Shop:

  def setPrice(self, price):
    assert(price >= 0 and price <= MAX_PRICE) # Noncompliant
    // Set the price

----

=== Compliant solution

[source,python]
----
class Shop:

  def setPrice(self, price):
    if(price < 0 or price > MAX_PRICE):
      raise ValueError("Invalid price: " + price)
    // Set the price

----

== Resources

* https://wiki.python.org/moin/UsingAssertionsEffectively[The Python Wiki, UsingAssertionsEffectively]
ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

include::../message.adoc[]

include::../highlighting.adoc[]

endif::env-github,rspecator-view[]
