News for hackers. Stuff that matters.
Re:Writing and Linting Python at Scale by insanitybit on Wednesday November 22, 2023 @02:11PM (#38383684)
Cool, guess they finally fixed this. Must've been in the last ~1 year, give or take. Of course, it relies on quoting your types, which is... a matter of taste, I suppose.
Re:Writing and Linting Python at Scale by dazzlefruit on Wednesday November 22, 2023 @02:18PM (#38383789)
Quoting types that are defined later is a wart but it's not very bad. VSCode's UI will happily handle it as if the quotes weren't there.
Re:Writing and Linting Python at Scale by npage97 on Wednesday November 22, 2023 @02:44PM (#38384129)
You can also use from __future__ import annotations so the quotes become unnecessary. https://peps.python.org/pep-0563/
Re:Writing and Linting Python at Scale by insanitybit on Wednesday November 22, 2023 @03:16PM (#38384530)
Does that work with recursive types? I have had mixed results with `from __future__ import annotations` personally, but I haven't written much Python in ~a year or so.
Re:Writing and Linting Python at Scale by FreakLegion on Wednesday November 22, 2023 @09:17PM (#38388394)
It's worked for many years, but you won't often see it used outside of class definitions because all of the other tools struggle with it (Pylint, Flake8, Pylance, etc. spit out some variation of an undefined variable error).
Re:Writing and Linting Python at Scale by insanitybit on Thursday November 23, 2023 @09:22AM (#38393050)
I don't think it has worked for years. I had used that same exact __annotations__ and my recollection was that recursive types still did not work.
Re:Writing and Linting Python at Scale by FreakLegion on Thursday November 23, 2023 @07:10PM (#38399297)
It's worked for years. I've been using it the whole time.