rspec/rules/S5886/python/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
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.
2023-05-25 14:18:12 +02:00

53 lines
1.2 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

== Why is this an issue?
Developers can use type hints to specify which type a function is expected to return. These annotations are not enforced at runtime and returning a different type might not fail. It is however likely to be unintended and will lead to maintainability issues, if not bugs.
This rule raises an issue when a function or method returns a value that contradicts its type hint.
=== Noncompliant code example
[source,python]
----
def hello() -> str:
return 42 # Noncompliant. Function's type hint asks for a string return value
----
=== Compliant solution
[source,python]
----
def hello() -> str:
return "Hello"
----
== Resources
* https://docs.python.org/3/library/typing.html[Python documentation - Support for type hints]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
*Return a "XXX" instead of a "YYY" or update function "ZZZ" type hint.
=== Highlighting
* If the function returns the wrong type:
** Primary: The return statement
**  Secondaries: 1. the function name, 2. The type hint
* If the function might terminate without reaching a return statement:
** Primary Location: The function name
** Secondary: the type hint
endif::env-github,rspecator-view[]