Skip to content

Commit 28a03fb

Browse files
authored
Fix various Pylint warnings (#40107)
Tidy code Signed-off-by: cyy <[email protected]>
1 parent ec85d2c commit 28a03fb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+70
-71
lines changed

examples/legacy/run_chinese_ref.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ def _is_chinese_char(cp):
1919
# like the all of the other languages.
2020
if (
2121
(cp >= 0x4E00 and cp <= 0x9FFF)
22-
or (cp >= 0x3400 and cp <= 0x4DBF) #
23-
or (cp >= 0x20000 and cp <= 0x2A6DF) #
24-
or (cp >= 0x2A700 and cp <= 0x2B73F) #
25-
or (cp >= 0x2B740 and cp <= 0x2B81F) #
26-
or (cp >= 0x2B820 and cp <= 0x2CEAF) #
22+
or (cp >= 0x3400 and cp <= 0x4DBF)
23+
or (cp >= 0x20000 and cp <= 0x2A6DF)
24+
or (cp >= 0x2A700 and cp <= 0x2B73F)
25+
or (cp >= 0x2B740 and cp <= 0x2B81F)
26+
or (cp >= 0x2B820 and cp <= 0x2CEAF)
2727
or (cp >= 0xF900 and cp <= 0xFAFF)
28-
or (cp >= 0x2F800 and cp <= 0x2FA1F) #
29-
): #
28+
or (cp >= 0x2F800 and cp <= 0x2FA1F)
29+
):
3030
return True
3131

3232
return False

src/transformers/commands/add_new_model_like.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def visit_SimpleStatementLine(self, node: cst.SimpleStatementLine):
9191
""".lstrip()
9292

9393

94-
class ModelInfos(object):
94+
class ModelInfos:
9595
"""
9696
Retrieve the basic informations about an existing model classes.
9797
"""

src/transformers/commands/chat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
import string
2323
import time
2424
from argparse import ArgumentParser, Namespace
25+
from collections.abc import AsyncIterator
2526
from dataclasses import dataclass, field
2627
from threading import Thread
27-
from typing import AsyncIterator, Optional
28+
from typing import Optional
2829

2930
import yaml
3031
from huggingface_hub import AsyncInferenceClient, ChatCompletionStreamOutput

src/transformers/commands/serving.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424
import threading
2525
import time
2626
from argparse import ArgumentParser, Namespace
27+
from collections.abc import Generator, Iterable
2728
from dataclasses import dataclass, field
2829
from io import BytesIO
2930
from threading import Thread
30-
from typing import Generator, Iterable, Optional, Union
31+
from typing import Optional, Union
3132

3233
from huggingface_hub import model_info
3334
from huggingface_hub.constants import HF_HUB_OFFLINE

src/transformers/modeling_utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,9 +1615,7 @@ def _find_mismatched_keys(
16151615
# This skips size mismatches for 4-bit weights. Two 4-bit values share an 8-bit container, causing size differences.
16161616
# Without matching with module type or parameter type it seems like a practical way to detect valid 4bit weights.
16171617
if not (
1618-
is_quantized
1619-
and new_state_dict[key].shape[-1] == 1
1620-
and new_state_dict[key].numel() * 2 == model_state_dict[key].numel()
1618+
is_quantized and tensor.shape[-1] == 1 and tensor.numel() * 2 == model_state_dict[key].numel()
16211619
):
16221620
mismatched_keys.append(key)
16231621
mismatched_shapes.append((tensor.shape, model_state_dict[key].shape))

src/transformers/models/convnext/modeling_tf_convnext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def call(
391391

392392
# Change the other hidden state outputs to NCHW as well
393393
if output_hidden_states:
394-
hidden_states = tuple([tf.transpose(h, perm=(0, 3, 1, 2)) for h in encoder_outputs[1]])
394+
hidden_states = tuple(tf.transpose(h, perm=(0, 3, 1, 2)) for h in encoder_outputs[1])
395395

396396
if not return_dict:
397397
hidden_states = hidden_states if output_hidden_states else ()

src/transformers/models/convnextv2/modeling_tf_convnextv2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def call(
439439

440440
# Change the other hidden state outputs to NCHW as well
441441
if output_hidden_states:
442-
hidden_states = tuple([tf.transpose(h, perm=(0, 3, 1, 2)) for h in encoder_outputs[1]])
442+
hidden_states = tuple(tf.transpose(h, perm=(0, 3, 1, 2)) for h in encoder_outputs[1])
443443

444444
if not return_dict:
445445
hidden_states = hidden_states if output_hidden_states else ()

src/transformers/models/cvt/modeling_tf_cvt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ def call(
784784
# Change back to (batch_size, num_channels, height, width) format to have uniformity in the modules
785785
hidden_state = tf.transpose(hidden_state, perm=(0, 3, 1, 2))
786786
if output_hidden_states:
787-
all_hidden_states = tuple([tf.transpose(hs, perm=(0, 3, 1, 2)) for hs in all_hidden_states])
787+
all_hidden_states = tuple(tf.transpose(hs, perm=(0, 3, 1, 2)) for hs in all_hidden_states)
788788

789789
if not return_dict:
790790
return tuple(v for v in [hidden_state, cls_token, all_hidden_states] if v is not None)

src/transformers/models/deepseek_vl/image_processing_deepseek_vl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def __init__(
125125
if image_mean is None:
126126
self.background_color = (127, 127, 127)
127127
else:
128-
self.background_color = tuple([int(x * 255) for x in image_mean])
128+
self.background_color = tuple(int(x * 255) for x in image_mean)
129129

130130
def resize(
131131
self,

src/transformers/models/deepseek_vl/image_processing_deepseek_vl_fast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def __init__(self, **kwargs: Unpack[DeepseekVLFastImageProcessorKwargs]):
6969
if kwargs.get("image_mean") is None:
7070
background_color = (127, 127, 127)
7171
else:
72-
background_color = tuple([int(x * 255) for x in kwargs.get("image_mean")])
72+
background_color = tuple(int(x * 255) for x in kwargs.get("image_mean"))
7373
self.background_color = tuple(background_color)
7474

7575
def resize(

0 commit comments

Comments
 (0)