
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
63 lines
1.5 KiB
Plaintext
63 lines
1.5 KiB
Plaintext
== Why is this an issue?
|
|
|
|
The CPython interpreter does not check arguments type when functions are called. However a function can express the type it expects for each argument in its documentation or by using https://www.python.org/dev/peps/pep-0484/[Type Hints]. Calling such a function with an argument of a different type can easily create a bug. Even if it works right now it can fail later when APIs evolve or when type checks are added (ex: with ``++isinstance++``).
|
|
|
|
|
|
This rule raises an issue when a function or method is called with an argument of a different type than the one described in its type annotations. It also checks argument types for builtin functions.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,python]
|
|
----
|
|
def func(var: str):
|
|
pass
|
|
|
|
func(42) # Noncompliant
|
|
|
|
len(1) # Noncompliant
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,python]
|
|
----
|
|
def func(var: str):
|
|
pass
|
|
|
|
func("42")
|
|
|
|
len("1")
|
|
----
|
|
|
|
|
|
== Resources
|
|
|
|
* https://docs.python.org/3/library/functions.html#built-in-funcs[Python documentation - builtins]
|
|
* https://www.python.org/dev/peps/pep-0484/[PEP 484 — Type Hints]
|
|
* https://docs.python.org/3/library/typing.html[Python documentation - typing — Support for type hints]
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
* Change this argument of type XXX; Function FFF expects type YYY
|
|
|
|
|
|
=== Highlighting
|
|
|
|
Primary: the expression provided as argument
|
|
|
|
Secondary:
|
|
|
|
* location: definition of the function called
|
|
* message: "Function definition"
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|