You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I believe this is the minimal amount of code necessary to reproduce the bug.
""" Functions for manipulating images stored within local content """classLocalImage:
""" The basic Image class, which knows about the base version and how to generate renditions from it """def_get_rendition(self, **kwargs):
""" implements get_rendition and returns tuple of out_rel_path,size,pending """_, box=self.get_rendition_size(kwargs)
ifbox:
box= (box[0], box[1], box[2], box[3])
defget_rendition_size(self, spec):
""" Wrapper to determine the overall rendition size and cropping box Returns tuple of (size,box) """width=spec.get('width', 100)
height=spec.get('height', 100)
mode=spec.get('resize', 'fit')
ifmode=='fit':
returnself.get_rendition_fit_size(width, height)
ifmode=='fill':
returnself.get_rendition_fill_size(width, height)
ifmode=='stretch':
returnself.get_rendition_stretch_size(width, height)
raiseValueError("Unknown resize mode {}".format(mode))
@staticmethoddefget_rendition_fit_size(input_w, input_h):
""" Determine the scale-crop size given the provided spec """return (input_w, input_h), None@staticmethoddefget_rendition_fill_size(input_w, input_h):
""" Determine the scale-crop size given the provided spec """return (input_w, input_h), (0, 0, input_w, input_h)
@staticmethoddefget_rendition_stretch_size(input_w, input_h):
""" Determine the scale-crop size given the provided spec """return (input_w, input_h), None
Current behavior
When I run pylint on this, I get errors:
************* Module pylint_repro
pylint_repro.py:14:19: E1136: Value 'box' is unsubscriptable (unsubscriptable-object)
pylint_repro.py:14:37: E1136: Value 'box' is unsubscriptable (unsubscriptable-object)
pylint_repro.py:15:19: E1136: Value 'box' is unsubscriptable (unsubscriptable-object)
pylint_repro.py:15:37: E1136: Value 'box' is unsubscriptable (unsubscriptable-object)
If I split lines 21 and 22 off into a separate function:
and replace line 21 with box = self._thunk_adjust_box(crop, box), the error disappears.
If in the method get_rendition_size I remove the lines for if mode == 'fit' the error disappears. However, the error remains if I leave that one present and remove the mode == 'stretch' lines.
Curiously, if I move the mode == 'fit' branch to go after the mode == 'fill' branch, the error also disappears.
This is peculiar since the value of box could be either tuple or NoneType regardless of the order of those branches, and anyway where the linter is throwing the error, box is guaranteed to not be NoneType.
This also still occurs if I change the box check to explicitly check for tuple, absolutely guaranteeing that box is a tuple in that code path:
Changing the class functions to be module-level functions causes the error to go away, which seems potentially interesting.
Expected behavior
This error should not be emitted, as box is always guaranteed to be a tuple on that code path, and the order of the proxy method branches within get_rendition_size shouldn't matter for that determination anyway.
Thanks for the great report. This issue is caused by the fact that pylint does not understand isinstance or if blocks, meaning that if a variable might be None in a branch and the code checks against that, pylint will ignore the if clause entirely, leading to false positives such as these ones. Almost all the topic-control-flow labeled issues are caused by this lack of isinstance / if guard understanding.
Possibly related to #2416
Steps to reproduce
I believe this is the minimal amount of code necessary to reproduce the bug.
Current behavior
When I run pylint on this, I get errors:
If I split lines 21 and 22 off into a separate function:
and replace line 21 with
box = self._thunk_adjust_box(crop, box)
, the error disappears.If in the method
get_rendition_size
I remove the lines forif mode == 'fit'
the error disappears. However, the error remains if I leave that one present and remove themode == 'stretch'
lines.Curiously, if I move the
mode == 'fit'
branch to go after themode == 'fill'
branch, the error also disappears.This is peculiar since the value of
box
could be eithertuple
orNoneType
regardless of the order of those branches, and anyway where the linter is throwing the error,box
is guaranteed to not beNoneType
.This also still occurs if I change the
box
check to explicitly check fortuple
, absolutely guaranteeing thatbox
is a tuple in that code path:Adding appropriate type hinting has no effect.
Changing the class functions to be module-level functions causes the error to go away, which seems potentially interesting.
Expected behavior
This error should not be emitted, as
box
is always guaranteed to be a tuple on that code path, and the order of the proxy method branches withinget_rendition_size
shouldn't matter for that determination anyway.pylint --version output
The text was updated successfully, but these errors were encountered: