On Fri, Oct 13, 2017, 6:34 AM Rudi Hammad <[email protected]> wrote:

> Hello,
>
> I usually turn off PEP 8 inspections in pycharm, but I gave it a try and
> turned inspections on to see what complains I get.
> I didn“t get much so far, but one that made me think if I am programming
> right is   "instance attribute defined outside __init__"
> Basically I am doing a UI in pyside, and as learned reading programming
> articles and also in this forum, I am trying to chop my code in as many
> methods as needed to keep things clean and easy to track.
> So I have a method called create_mainLayout() where I organize the big
> layout blocks. I write something like this:
>
> def create_mainLayout(self):
>
>     self.L_vLao = QtGui.QVBoxLayout()
>     bla bla bla
>
> And here is where I get the PEP 8 complain mentioned:  "instance attribute 
> defined outside __init__"
>
> The reason why I do this is because then I have another method that picks up 
> this self.L_vLao to get into more detail.
> So if i want to use a variable created in another method, I have no choice 
> but using self.
> I thought creating self.something inside methods was okey.
>
> Is my code badly designed?
>
>
It's a readability warning suggesting that it may make it harder for others
to see where attributes are defined when they are initialized from other
methods. It can also warn about potential bugs if you were to reorder
methods in your init and accidentally put a method that uses the attribute
before the one that defines it.

You can satisfy PyCharm by initializing the attribute to None in your init.
This should also allow your auto-complete to report the attribute for your
class, if it doesn't already. Or you could disable the warning and choose
not to make that part of your style.


> Thank you,
> R
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/5e4ad9fa-ebfb-4868-ad92-1391d1efca29%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/5e4ad9fa-ebfb-4868-ad92-1391d1efca29%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2p0mLUesYivZTJN93pnx-awjeU_OZxg_C5ze6rX1AexA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to