Page MenuHomePhabricator

isort: allow skipping add future annotation imports per file
Closed, ResolvedPublicFeature

Description

Current Behaviour
isort is currently configured to automatically add from __future__ import annotations to Python modules. However, some files (e.g. configuration modules like pywikibot/config.py or bootstrap scripts such as pwb.py) must not receive this import. At the moment, pwb.py is excluded from the isort hook entirely.

Proposal
Provide a way to exclude specific files from automatically adding the future import while keeping all other isort functionality (e.g. import sorting and formatting) enabled for given files.

Event Timeline

Xqt changed the task status from Open to In Progress.Fri, Feb 6, 10:14 AM
Xqt triaged this task as High priority.
Xqt changed the subtype of this task from "Task" to "Feature Request".
Xqt renamed this task from isort: allow skipping add_future annotation imports per file to isort: allow skipping add future annotation imports per file.Fri, Feb 6, 10:23 AM

Change #1237462 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] isort: allow skipping add future annotation imports per file

https://gerrit.wikimedia.org/r/1237462

Change #1237462 merged by jenkins-bot:

[pywikibot/core@master] isort: allow skipping add future annotation imports per file

https://gerrit.wikimedia.org/r/1237462

Hi @JJMC89, I noticed you dislike this task. This also affects T416145. Since I really value your technical judgement, I’d like to understand your concerns better. Could you share what you think is problematic about it.

Xqt added a project: Pywikibot-RfCs.

Its not technically problematic. I was just expressing my dislike of the inconsistency in type annotations it creates across the library. The better options is to drop support for EOL python3.9 now or wait until we do. (Also change globals().get('__annotations__', {}) to typing.get_type_hints(sys.modules[__name__]).)

Its not technically problematic. I was just expressing my dislike of the inconsistency in type annotations it creates across the library. The better options is to drop support for EOL python3.9 now or wait until we do. (Also change globals().get('__annotations__', {}) to typing.get_type_hints(sys.modules[__name__]).)

Good catch, thanks a lot. I'll postpone the parent task to Pywikikibot 12.

Change #1239533 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] Only skip pwb.py from adding future annotations.

https://gerrit.wikimedia.org/r/1239533

Change #1239533 merged by jenkins-bot:

[pywikibot/core@master] Only skip pwb.py from adding future annotations.

https://gerrit.wikimedia.org/r/1239533