There is a redirect [[https://test.wikipedia.org/w/index.php?title=File:Invalid.ext&redirect=no |File:Invalid.ext]] on test wiki in File namespace.
`randompages()` tries to upcast to a FilePage but fails due to invalid extension
```
13:19:45 ======================================================================
13:19:45 ERROR: test_redirects (tests.site_generators_tests.SiteRandomTestCase)
13:19:45 Test site.randompages() with redirects.
13:19:45 ----------------------------------------------------------------------
13:19:45 Traceback (most recent call last):
13:19:45 File "/src/tests/site_generators_tests.py", line 1579, in test_redirects
13:19:45 for rndpage in mysite.randompages(total=5, redirects=True):
13:19:45 File "/usr/lib/python3.6/_collections_abc.py", line 317, in __next__
13:19:45 return self.send(None)
13:19:45 File "/src/pywikibot/tools/collections.py", line 275, in send
13:19:45 return next(self._started_gen)
13:19:45 File "/src/pywikibot/data/api/_generators.py", line 619, in generator
13:19:45 yield from self._extract_results(resultdata)
13:19:45 File "/src/pywikibot/data/api/_generators.py", line 563, in _extract_results
13:19:45 result = self.result(item)
13:19:45 File "/src/pywikibot/data/api/_generators.py", line 722, in result
13:19:45 p = pywikibot.FilePage(p)
13:19:45 File "/src/pywikibot/page/_filepage.py", line 62, in __init__
13:19:45 f'{title!r} does not have a valid extension '
13:19:45 ValueError: 'File:Invalid.ext' does not have a valid extension (djvu, flac, gif, jpeg, jpg, mid, midi, mp3, mpeg, mpg, oga, ogg, ogv, opus, pdf, png, stl, svg, tif, tiff, wav, webm, webp, xcf).
13:19:45
```
Maybe the redirect status should be checked first before the extension is checked. Or can we have a Page object in namespace 6 which is not a FilePage?
This behaviour was introduced with T345786 (rPWBC8c86bcb)