Skip to content

Improve code style: fix imports and PEP 8 violations#52

Merged
ZHZisZZ merged 4 commits intodevfrom
copilot/improve-code-style
Dec 13, 2025
Merged

Improve code style: fix imports and PEP 8 violations#52
ZHZisZZ merged 4 commits intodevfrom
copilot/improve-code-style

Conversation

Copy link
Contributor

Copilot AI commented Dec 13, 2025

Reduces stylistic inconsistencies across the codebase while preserving all functionality. Models directories remain untouched per existing black configuration.

Import Organization

  • Sorted imports with isort (black profile) across 60+ files
  • Removed unused type imports (Optional, Dict, List, Type) from data loaders and schedulers

PEP 8 Compliance

  • Replaced bare except: with except Exception:
  • Fixed None comparisons: != Noneis not None
  • Removed trailing whitespace from example files
Original prompt

Improve code style and reduce stylistic inconsistencies with minimal changes. Exclude files under xx/models/.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Improve code style and reduce inconsistencies Improve code style: fix variable names, imports, and PEP 8 violations Dec 13, 2025
Copilot AI requested a review from ZHZisZZ December 13, 2025 13:33
@ZHZisZZ
Copy link
Owner

ZHZisZZ commented Dec 13, 2025

@copilot

revert the following changes: "Renamed ambiguous single-letter variable l → seq_len in trainer and evaluation code"

Copy link
Contributor Author

Copilot AI commented Dec 13, 2025

@copilot

revert the following changes: "Renamed ambiguous single-letter variable l → seq_len in trainer and evaluation code"

Reverted the variable name changes (l → seq_len) in commit 2149c42. The original variable names are restored while preserving the import ordering improvements.

Copilot AI changed the title Improve code style: fix variable names, imports, and PEP 8 violations Improve code style: fix imports and PEP 8 violations Dec 13, 2025
Copilot AI requested a review from ZHZisZZ December 13, 2025 13:40
@ZHZisZZ ZHZisZZ marked this pull request as ready for review December 13, 2025 13:43
@ZHZisZZ ZHZisZZ requested a review from Copilot December 13, 2025 13:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves code consistency and adherence to Python style guidelines across 60+ files in the codebase while preserving all functionality. The changes focus on import organization and PEP 8 compliance.

Key changes:

  • Applied isort with black profile to organize imports across the codebase (stdlib → third-party → local)
  • Replaced bare except: clauses with except Exception: for better exception handling practices
  • Fixed PEP 8 None comparisons (!= Noneis not None)
  • Removed trailing whitespace from documentation and example files
  • Removed unused type hint imports that were not referenced in the code

Reviewed changes

Copilot reviewed 60 out of 66 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
scripts/tests/test_attention.py Sorted imports: pytest moved after third-party imports
examples/llada/sft.py, pt.py, chat.py Removed trailing whitespace; sorted imports (accelerate before transformers)
examples/editflow/*.py Sorted imports alphabetically; removed trailing whitespace from comments
examples/dream/*.py Sorted imports; removed trailing whitespace from documentation
examples/bert/*.py Sorted imports; removed trailing whitespace
examples/a2d//.py Sorted imports; removed trailing whitespace
dllm/utils/visualizers.py Sorted imports from rich library alphabetically; sorted stdlib imports
dllm/utils/utils.py Sorted imports: logging before os; alphabetized third-party imports
dllm/utils/models.py Fixed bare except → except Exception; fixed None comparison to use is not None; sorted imports
dllm/utils/data.py Sorted imports; alphabetized TYPE_CHECKING imports
dllm/utils/configs.py Alphabetized local imports
dllm/utils/collators.py Moved typing import to proper position with blank line separator
dllm/utils/chat.py Moved typing imports after stdlib; removed extra blank lines
dllm/utils/init.py Alphabetized import order
dllm/tools/*.py Sorted imports alphabetically
dllm/pipelines/*/eval.py Sorted imports: moved tqdm after lm_eval imports
dllm/pipelines/*/init.py Alphabetized imports for consistency
dllm/pipelines/editflow/utils.py Alphabetized typing imports
dllm/pipelines/editflow/trainer.py Alphabetized typing imports; removed extra blank lines
dllm/pipelines/dream/sampler.py Sorted imports: torch.distributions after torch.nn.functional
dllm/data/*.py Removed unused type imports (Optional, List, Dict); sorted remaining imports
dllm/core/trainers/*.py Moved typing imports to proper position after from future
dllm/core/schedulers/*.py Removed unused type imports (Dict, Type); added blank line after future
dllm/core/samplers/*.py Sorted base imports alphabetically; removed multi-line import formatting

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

from .data import *
from .sampling import *
from .models import *
from .sampling import *
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

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

Import pollutes the enclosing namespace, as the imported module dllm.utils.sampling does not define 'all'.

Copilot uses AI. Check for mistakes.

if TYPE_CHECKING:
from dllm.utils.configs import ModelArguments, DataArguments, TrainingArguments
from dllm.utils.configs import DataArguments, ModelArguments, TrainingArguments
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

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

Import of 'ModelArguments' is not used.
Import of 'TrainingArguments' is not used.

Copilot uses AI. Check for mistakes.

from dllm.utils.utils import disable_caching_allocator_warmup, print_main, load_peft
from dllm.utils.configs import ModelArguments, TrainingArguments
from dllm.utils.utils import disable_caching_allocator_warmup, load_peft, print_main
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

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

Import of 'disable_caching_allocator_warmup' is not used.

Copilot uses AI. Check for mistakes.

import os
from dataclasses import dataclass, asdict
from dataclasses import asdict, dataclass
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

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

Import of 'asdict' is not used.

Copilot uses AI. Check for mistakes.
from dataclasses import dataclass, asdict
from dataclasses import asdict, dataclass
from functools import partial
from pprint import pprint
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

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

Import of 'pprint' is not used.

Copilot uses AI. Check for mistakes.
import logging
from contextlib import contextmanager
from dataclasses import dataclass, asdict
from dataclasses import asdict, dataclass
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

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

Import of 'dataclass' is not used.

Copilot uses AI. Check for mistakes.
from typing import Any, Dict, List, Optional, Tuple, Text
from collections.abc import Callable
from dataclasses import dataclass
from typing import Any, Dict, List, Optional, Text, Tuple
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

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

Import of 'Dict' is not used.
Import of 'List' is not used.
Import of 'Tuple' is not used.
Import of 'Optional' is not used.
Import of 'Text' is not used.

Suggested change
from typing import Any, Dict, List, Optional, Text, Tuple
from typing import Any

Copilot uses AI. Check for mistakes.
import re
import unicodedata
from typing import Optional, List, Tuple, Annotated
from typing import Annotated, List, Optional, Tuple
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

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

Import of 'Tuple' is not used.
Import of 'Optional' is not used.
Import of 'Annotated' is not used.

Copilot uses AI. Check for mistakes.
from typing import Optional, List, Tuple, Annotated
from typing import Annotated, List, Optional, Tuple

from PIL import Image, ImageDraw, ImageFont
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

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

Import of 'Image' is not used.
Import of 'ImageDraw' is not used.
Import of 'ImageFont' is not used.

Copilot uses AI. Check for mistakes.
from abc import ABC, abstractmethod
from typing import Sequence, Optional
from dataclasses import dataclass
from typing import Optional, Sequence
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

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

Import of 'Sequence' is not used.

Copilot uses AI. Check for mistakes.
@ZHZisZZ ZHZisZZ merged commit d73203d into dev Dec 13, 2025
7 checks passed
@ZHZisZZ ZHZisZZ deleted the copilot/improve-code-style branch January 1, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants