rspec/rules/S5886/python/rule.adoc

38 lines
889 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
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.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
def hello() -> str:
return 42 # Noncompliant. Function's type hint asks for a string return value
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
def hello() -> str:
return "Hello"
----
2021-04-28 16:49:39 +02:00
== See
* 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)
include::message.adoc[]
include::highlighting.adoc[]
endif::env-github,rspecator-view[]