In the current code, pywikibot.handleArgs() must be called before pagegenerators.GeneratorFactory(), as pagegenerators.GeneratorFactory.__init__() calls pywikibot.Site().
If pagegenerators.GeneratorFactory() is called first, the default site per user-config is used, and command line args (-family -lang -user) are ignored. See bug 63800.
This could be almost completely fixed by changing GeneratorFactory.site to be a property, loaded on access. That prevents the typical coding bug which look like:
genFactory = pagegenerators.GeneratorFactory() for arg in pywikibot.handleArgs(): if genFactory.handleArg(arg): pass
The current solution is to use and promote the pattern:
local_args = pywikibot.handleArgs() genFactory = pagegenerators.GeneratorFactory() for arg in local_args: if genFactory.handleArg(arg): pass
However it doesnt prevent this:
genFactory = pagegenerators.GeneratorFactory() genFactory.handleArg('-file:' + filename): ... pywikibot.handleArgs()
One way to prevent that is to raise an exception in pywikibot.handleArgs if it is called after pywikibot.Site() has instantiated a default site, and possibly only if -family/-lang/-user are supplied on the command line.
Another approach (very dodgy) is for pywikibot to know which Site object is the 'default' site, and pywikibot.handleArgs() change that object if -family/-lang/-user are supplied on the command line.
See Also: T65800