Xqt added a comment.

  You plan looks good. Another idea would be to remove the `from __future__ 
import annotations` line. In that case, you get the classes directly without 
parsing. For example:
  
    >>> hint = config.__annotations__['put_throttle']
    >>> hint.__args__
    (<class 'int'>, <class 'float'>)
    >>> config.__annotations__['authenticate']
    >>> hint.__origin__
    <class 'dict'>
  
  You should test `__origin__` first. This will fail with `AttributeError` for 
`UnionType`s. In which case `__args__` is the correct choice.
  
  Unfortunately, we still support Python 3.9 (until the end of this year) and 
PEP604 <https://peps.python.org/pep-0604/> was implemented in Python 3.10. 
Therefore, for Python 3.9 compatibility, all unions must be written as 
`Union[]` or `Optional[]`.
  
  The import is per file and there are only 11 occurrences to fix in config.py 
(you can check with `pre-commit run mypy -a` for this check) . It's up to you 
which approach is the best : either use the annotations directly or implement 
your own parser. I propose using the first approach, because deferred 
evaluation (without __anotations__ import) is the default in Python 3.14+, and 
storing annotation as strings will be eventually be removed [1 
<https://docs.python.org/3.15/library/__future__.html#id2>].

TASK DETAIL
  https://phabricator.wikimedia.org/T416145

EMAIL PREFERENCES
  https://phabricator.wikimedia.org/settings/panel/emailpreferences/

_______________________________________________
pywikibot-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to