Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/packaging/_elffile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

from __future__ import annotations

__lazy_modules__ = ["os", "struct", "typing"]

import enum
import os
import struct
Expand Down
2 changes: 2 additions & 0 deletions src/packaging/_manylinux.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

__lazy_modules__ = [f"{__spec__.parent}._elffile", "os", "re", "sys", "warnings"]

import collections
import contextlib
import functools
Expand Down
2 changes: 2 additions & 0 deletions src/packaging/_musllinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from __future__ import annotations

__lazy_modules__ = [f"{__spec__.parent}._elffile", "subprocess"]

import functools
import re
import subprocess
Expand Down
2 changes: 2 additions & 0 deletions src/packaging/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from __future__ import annotations

__lazy_modules__ = ["ast", f"{__spec__.parent}._tokenizer"]

import ast
from typing import List, Literal, NamedTuple, Sequence, Tuple, Union

Expand Down
2 changes: 2 additions & 0 deletions src/packaging/_tokenizer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

__lazy_modules__ = ["contextlib", "typing"]

import contextlib
import re
from dataclasses import dataclass
Expand Down
7 changes: 7 additions & 0 deletions src/packaging/dependency_groups.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
from __future__ import annotations

__lazy_modules__ = [
"collections",
"collections.abc",
f"{__spec__.parent}.errors",
f"{__spec__.parent}.requirements",
]

import re
from collections.abc import Mapping, Sequence

Expand Down
2 changes: 2 additions & 0 deletions src/packaging/direct_url.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

__lazy_modules__ = ["collections", "collections.abc", "urllib", "urllib.parse"]

import dataclasses
import re
import urllib.parse
Expand Down
2 changes: 2 additions & 0 deletions src/packaging/errors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

__lazy_modules__ = ["builtins", "contextlib", "typing"]

import contextlib
import dataclasses
import sys
Expand Down
2 changes: 2 additions & 0 deletions src/packaging/licenses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#######################################################################################
from __future__ import annotations

__lazy_modules__ = [f"{__spec__.parent}._spdx"]

import re
from typing import NewType, cast

Expand Down
10 changes: 10 additions & 0 deletions src/packaging/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

from __future__ import annotations

__lazy_modules__ = [
f"{__spec__.parent}._parser",
f"{__spec__.parent}._tokenizer",
f"{__spec__.parent}.specifiers",
f"{__spec__.parent}.utils",
"os",
"platform",
"sys",
]

import operator
import os
import platform
Expand Down
2 changes: 2 additions & 0 deletions src/packaging/metadata.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

__lazy_modules__ = [f"{__spec__.parent}.errors", "keyword", "pathlib"]

import email.header
import email.message
import email.parser
Expand Down
12 changes: 12 additions & 0 deletions src/packaging/pylock.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
from __future__ import annotations

__lazy_modules__ = [
"collections",
"collections.abc",
"datetime",
f"{__spec__.parent}.markers",
f"{__spec__.parent}.specifiers",
f"{__spec__.parent}.utils",
f"{__spec__.parent}.version",
"urllib",
"urllib.parse",
]

import dataclasses
import logging
import re
Expand Down
9 changes: 9 additions & 0 deletions src/packaging/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
# for complete details.
from __future__ import annotations

__lazy_modules__ = [
f"{__spec__.parent}._parser",
f"{__spec__.parent}._tokenizer",
f"{__spec__.parent}.markers",
f"{__spec__.parent}.specifiers",
f"{__spec__.parent}.utils",
"typing",
]

from typing import Iterator

from ._parser import parse_requirement as _parse_requirement
Expand Down
2 changes: 2 additions & 0 deletions src/packaging/specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

from __future__ import annotations

__lazy_modules__ = [f"{__spec__.parent}.utils", "itertools"]

import abc
import itertools
import re
Expand Down
10 changes: 10 additions & 0 deletions src/packaging/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

from __future__ import annotations

__lazy_modules__ = [
"importlib",
"importlib.machinery",
"platform",
"re",
"subprocess",
"sys",
"sysconfig",
]

import logging
import platform
import re
Expand Down
2 changes: 2 additions & 0 deletions src/packaging/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from __future__ import annotations

__lazy_modules__ = [f"{__spec__.parent}.tags", f"{__spec__.parent}.version"]

import re
from typing import NewType, Tuple, Union, cast

Expand Down
2 changes: 2 additions & 0 deletions src/packaging/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

from __future__ import annotations

__lazy_modules__ = ["functools", "warnings"]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functools are only imported for python <3.13 so having it here seems pointless?
Also is having warnings here really worth it, it's a tiny dependency and very likely imported from elsewhere anyway...

Copy link
Copy Markdown
Contributor Author

@henryiii henryiii Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's automated based on rules - if it's not used at top level, it shows up here. (https://flake8-lazy.readthedocs.io). Not sure it's worth adding complexity for the python version case.


import re
import sys
import typing
Expand Down
Loading