Reconsider NVDA code style, linting and auto formatting #15299
Replies: 11 comments 9 replies
-
We'd like to hear more community feedback here. If we end up dropping tabs for spaces, would that affect anyone? If we end up switching over, we will be refactoring the entire code base. |
Beta Was this translation helpful? Give feedback.
-
As an update that is probably pretty relevant to us, the experimental formatter in Ruff now supports tab indentation. The formatter in Ruff is mostly based on Black. Black usually follows the code style NVDA uses, except for the extra level of indentation PEP8 and NVDA use for function parameters. |
Beta Was this translation helpful? Give feedback.
-
You brought up several thinks here, which are IMHO, more or less independent from each other. While I sort of understand that fixing all your gripes with NVDA's code formatting in one step is tempting, aiming for something that big may mean nothing gets done. In contrast I'd like to suggest moving in smaller steps, and reducing scope of this discussion:
As to the tabs vs spaces from the technical side I am personally indifferent, however it would be good to have opinions from people contributing regularly who may have different perspectives. In particular I'm curious what @CyrilleB79 thinks - I believe you are using some remaining vision, and when discussing tabs for accessibility their configurability for VI programmers is often mentioned. I would also be nice to know why tabs were used in the first place from either @jcsteh or @michaelDCurran - I've never found the Notepad++ argument much convincing, since with correct configuration it can also auto-indent similarly to VSCode / PyCharm. |
Beta Was this translation helpful? Give feedback.
-
Hello!
Às 18:03 de 10/10/2023, Łukasz Golonka
escreveu:
As to the tabs vs spaces from the technical side I
am personally indifferent, however it would be good to have
opinions from people contributing regularly who may have
different perspectives.
Regarding technical side, I do not know...
But, for a Braille display user, having tabs instead of spaces
save a lot of cells!
I have already seen code with 4 spaces intead of a tab... In a 40
cells Braille display, 16 spaces instead of 4 tabs use almost half
of the display...
Rui Fontes
|
Beta Was this translation helpful? Give feedback.
-
It seems that our current version of flake8 doesn't support modern python syntax such as the walrus operator |
Beta Was this translation helpful? Give feedback.
-
Hi, In this case, I vote for Ruff (there is a PyPI package that will convert Flake8 config file to pyproject.toml for use by Ruff and other tools) unless Flake8-tabs can be maintained somehow (likely not). The fact that Flake8 3.9.2 does not support syntax introduced in Python 3.8 and later blocks people frof submitting/implementing things such as assignment expressions and structured pattern matching (these two can modernize conditional statements and loops scattered throughout NVDA code base and add-ons). Thanks. |
Beta Was this translation helpful? Give feedback.
-
For most contributors linting is an automatic process - the developer just executes a script, and the list of eventual violations is shown, so I'm not sure what, aside from the change of indentation standard, can be confusing here.
I was never, regardless o what is discussed, convinced by arguments like these. As mentioned above we automate linting for contributors, (I assume we would aim to automate reformatting as well), so what happens under the hood is not that important.
Thanks - I've looked for a similar solution before commenting here, but didn't manage to find anything useful.
Given the latest issues with our old version of Flake8 not supporting the walrus operator, it seems circumstances has changed slightly. |
Beta Was this translation helpful? Give feedback.
-
To move this forward I have contacted author of flake8-tabs, to establish if this plugin is going to be maintained in the future, as that may influence our decisions. |
Beta Was this translation helpful? Give feedback.
-
I'm trying to help a blind user (experienced C++ VStudio user) read python.py files. Python's lack of a clearly defined end statement such as ";" or "{...}" (like in C++ or perl) makes it very difficult reading python code with a JAWS reader. |
Beta Was this translation helpful? Give feedback.
-
Hi Luke,
thanks for your response - I really did not expect an answer.
My blind friend & I are coders from the old days of C/C++ and Perl.
We’re comfortable working with visible markers defining start/end of code blocks.
I’m in the process of implementing something similar along
the lines you suggested [ #{ … #} ] to give him better python guidance
while navigating blank line sounds coming from his JAWS reader.
Thanks.
-Klaus.
P.S. He will be my beta tester for sure.
… On Oct 27, 2023, at 2:16 AM, Luke Davis ***@***.***> wrote:
@kds215 <https://github.com/kds215> While this is off topic for this discussion, I will give you at least one response.
What you describe is the oldest problem faced by blind Python coders.
The solutions I know are:
Use a feature which indicates indentation. NVDA provides a tones based indentation marker that works well for this if coding in NotepadPlusPlus or any text editor.
You can also use normal "X spaces Y tabs" indentation notices, though personally my brain works better with beeps.
Also, hopefully the access software is smart enough to only tell you about indentation when it changes, so you only have to remember at what indent level your class, method, etc. starts. Since most classes and methods and such will share the same indent level as others of the same kind, this becomes second nature.
Use a 40/80 cell braille display to give you a "feel" for indentation.
Use an editor that provides indent based block collapse/expand. Notepad++ does this.
In that case, collapse the blocks you aren't working on, and expand the ones you are.
Use an IDE which provides some sort of segregation/containerization. I have not used Visual Studio/VS Code, but I'm sure there is a workable mechanism therein as a lot of blind coders do use those IDEs.
While learning and getting used to things, there is technically nothing wrong with putting braces in comments, as long as you also remember to indent appropriately. For example:
if myVariable is None: #{
doSomething()
doSomethingElse() #}
else: #{
andNow.forSomethingCompletelyDifferent() #}
(or whatever placement seems wise to the user)
Of course, no production code should look like that, and the user will have to get over it quickly, but it may help while learning.
—
Reply to this email directly, view it on GitHub <#15299 (reply in thread)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AHB65GNH2OOM73QYSXIE7PLYBNGSPAVCNFSM6AAAAAA3QXYWVOVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM3TGOJZHE4TA>.
You are receiving this because you were mentioned.
|
Beta Was this translation helpful? Give feedback.
-
I created astral-sh/ruff#8360 as the only remaining show stopper in the Ruff autoformatter for us. |
Beta Was this translation helpful? Give feedback.
-
With our switch to a newer Python coming closer and closer, I'd like to bring up a controversial subject again, namely the NVDA code style, linting and auto formatting.
Lately, Microsoft Visual Studio Code has become a major game changer in development for blind and visually impaired folks because it is a accessibility focused IDE with many features that make life of a developer a charm. To put it another way, the days of coding in NotePad++ lay or should lay far behind us. However, the developments in Code do not stand still, and recently they dropped support for the older version of Flake8 we're using. That brings us to the first problem, we are stukc to an older version of Flake8 because we rely on Flake8tabs and that Python extension is no longer maintained. It also brings me to the first controversial suggestion, switching from tabs to spaces for indentation. I have worked with both Visual Studio and VS Code for several years now, and apart from the case where space indentation takes more space on a braille display, I see no disadvantages, as a modern IDE can handle this very well.
Switching from tabs to spaces means that we can rely on the most recent version of Flake8, however when we consider changing this, I think we should also consider automatic code formatting with a reliable formatter like Black. To be honest, I think that the NVDA project puts too much code formatting burden on the shoulders of code contributors. Furthermore, after several years of enforcing a code formatting style for the NVDA source code, I still pretty often find myself in a situation where I have to edit code and reformat it in the process. Honestly, I believe that in modern times, not using automatic formatting of our Python and C++ code is a major disadvantage and cause of disappointment.
Beta Was this translation helpful? Give feedback.
All reactions