Replies: 1 comment 3 replies
-
Sorry I missed this, it doesn't seem like discussions have webhooks implemented.
In my opinion this is fair in general, but the decorator definition case presents a reasonable scenario where annotations might not add value and you'd have to
Difficulty depends. Conceptually, it would be great to be able to explicitly special case decorator definitions but there's no great way to reliably identify these statically and within the per-file context of flake8. Something similar to #99 might be beneficial if |
Beta Was this translation helpful? Give feedback.
-
Currently nested functions are considered public since they can trigger e.g.
ANN201
. Of course such errors could be circumvented by prefixing the name with an underscore or with anoqa
. However, nested functions are only within the scope of the parent function, so they aren't necessarily public despite their naming convention. Conceptually, they could be considered public if they are returned and used elsewhere.The area in which this issue often comes up is in the implementation of decorators. It is often redundant to annotate the nested wrapper function because it uses
functools.wraps
to carry over annotations. There are exceptions in cases of greater complexity. For example, some decorators wrap the return value in a consistent object or explicitly use certain arguments so the annotations can be an aid in explaining the nearby code.Do you think the plugin should treat nested functions differently in this regard, or is it fair and not much of an inconvenience to just prefix their names with an underscore? Would this be a difficult feature to implement? Should it be opt-in behaviour or even have a separate set of errors?
Beta Was this translation helpful? Give feedback.
All reactions