Fix correctness issues caused by reusing boilerplate code

There are two instances where a variable from a previous for-loop body
is reused in an unrelated for-loop. It works by accident, but stores or
prints the wrong element. The one for unions is particularly concerning
since it maps the same random record (from the previous loop) to all
union identifiers, leading to an incorrect index.

There is another location where an assignment was forgotten. It is a
"time bomb" since some codebase could trigger the code reading
cls_method_desc when it's not previously defined
(cls_method.doc is None branch), causing a runtime exception.
3 jobs for fix-copypaste in 1 minute and 46 seconds
Status Job ID Name Coverage
  Check
passed #1243624
flake8

00:01:28

failed #1243625
allowed to fail
mypy

00:01:42

passed #1243626
reuse

00:01:46

 
Name Stage Failure
failed
mypy Check
gidocgen/gir/parser.py:925: error: Argument "get_type" to "GType" has incompatible type "Optional[str]"; expected "str"
gidocgen/gir/parser.py:968: error: Argument "get_type" to "GType" has incompatible type "Optional[str]"; expected "str"
gidocgen/gir/parser.py:990: error: Argument "name" to "Union" has incompatible type "Optional[str]"; expected "str"
gidocgen/gir/parser.py:990: error: Argument "symbol_prefix" to "Union" has incompatible type "Optional[str]"; expected "str"
gidocgen/gir/parser.py:990: error: Argument "ctype" to "Union" has incompatible type "Optional[str]"; expected "str"
gidocgen/utils.py:767: error: Need type annotation for 'found_programs' (hint: "found_programs: Dict[<type>, <type>] = ...")
Found 186 errors in 4 files (checked 16 source files)
Cleaning up file based variables
ERROR: Job failed: exit code 1