onnx
Add type annotations and fix some lint warnings in Python code
#6470
Merged

Add type annotations and fix some lint warnings in Python code #6470

justinchuby merged 4 commits into onnx:main from cyyever:pylint
cyyever
cyyever215 days ago (edited 215 days ago)

Description

More robust type checking in Python.

Motivation and Context

For better code.

cyyever cyyever requested a review 215 days ago
cyyever cyyever requested a review 215 days ago
codecov
codecov215 days ago (edited 214 days ago)

Codecov Report

Attention: Patch coverage is 42.85714% with 24 lines in your changes missing coverage. Please review.

Project coverage is 57.23%. Comparing base (b73d819) to head (165a6db).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
onnx/compose.py 0.00% 10 Missing and 10 partials ⚠️
onnx/gen_proto.py 0.00% 2 Missing ⚠️
onnx/helper.py 94.11% 1 Missing ⚠️
onnx/utils.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6470   +/-   ##
=======================================
  Coverage   57.23%   57.23%           
=======================================
  Files         507      507           
  Lines       31443    31445    +2     
  Branches     3542     3542           
=======================================
+ Hits        17997    17999    +2     
  Misses      12597    12597           
  Partials      849      849           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

cyyever cyyever force pushed from b6965aad to 4c9cc638 215 days ago
github-advanced-security
github-advanced-security commented on 2024-10-19
onnx/backend/base.py
7777 @classmethod
7878 def is_compatible(
79 cls, model: ModelProto, device: str = "CPU", **kwargs: Any # noqa: ARG003
79 cls,
80
**kwargs: Any,
github-advanced-security215 days ago

RUFF/ARG003

Unused class method argument: kwargs.
See https://docs.astral.sh/ruff/rules/unused-class-method-argument

Show more details

onnx/backend/base.py
8586 def prepare(
86 cls, model: ModelProto, device: str = "CPU", **kwargs: Any # noqa: ARG003
87 ) -> BackendRep | None:
88 # TODO Remove Optional from return type
87 cls,
88 model: ModelProto,
89
**kwargs: Any,
github-advanced-security215 days ago

RUFF/ARG003

Unused class method argument: kwargs.
See https://docs.astral.sh/ruff/rules/unused-class-method-argument

Show more details

onnx/helper.py
670672
671673 arr = func(array_flat[0::2], array_flat[1::2])
672 return arr.astype(np.uint8) # type: ignore[no-any-return]
674
return arr.astype(np.uint8)
github-advanced-security215 days ago

MYPY/no-any-return

Returning Any from function declared to return "ndarray[Any, Any]"

To disable, use # type: ignore[no-any-return]

Show more details

onnx/helper.py
github-advanced-security215 days ago

MYPY/arg-type

Argument 1 to "CopyFrom" of "TensorProto" has incompatible type "Any | None"; expected "Message"

To disable, use # type: ignore[arg-type]

Show more details

cyyever cyyever force pushed from d7fdf88a to c9ca3e1d 215 days ago
github-advanced-security
github-advanced-security commented on 2024-10-19
onnx/backend/test/runner/__init__.py
410410 inits = {i.name for i in onx.graph.initializer}
411411 n_input = 0
412412 inputs = []
413 for i in range(len(onx.graph.input)):
414 if onx.graph.input[i].name in inits:
413
for i, x in enumerate(onx.graph.input):
github-advanced-security215 days ago

RUFF/B007

Loop control variable i not used within loop body.
See https://docs.astral.sh/ruff/rules/unused-loop-control-variable

Show more details

cyyever cyyever force pushed from c9ca3e1d to 7f0ca625 215 days ago
github-advanced-security
github-advanced-security commented on 2024-10-19
onnx/helper.py
387387
388388
389def float32_to_float8e4m3( # noqa: PLR0911
389
def float32_to_float8e4m3(
github-advanced-security215 days ago

RUFF/PLR0911

Too many return statements (9 > 6).
See https://docs.astral.sh/ruff/rules/too-many-return-statements

Show more details

cyyever cyyever force pushed from f9db56f4 to e4054f2e 215 days ago
cyyever cyyever force pushed from e4054f2e to 43c40988 215 days ago
cyyever cyyever force pushed from 43c40988 to aff4af47 215 days ago
justinchuby
justinchuby commented on 2024-10-19
Conversation is marked as resolved
Show resolved
onnx/gen_proto.py
66import argparse
77import glob
88import os
9
import os.path
justinchuby215 days ago
Suggested change
import os.path
justinchuby
justinchuby commented on 2024-10-19
Conversation is marked as resolved
Show resolved
onnx/hub.py
363364 "download the model from the model hub."
364365 )
365366
366 # FIXME: Avoid index manipulation with magic numbers,
367367
# remove ".tar.gz"
justinchuby215 days ago
Suggested change
# remove ".tar.gz"
justinchuby
justinchuby approved these changes on 2024-10-19
justinchuby215 days ago

Thanks!

justinchuby
justinchuby215 days ago

There is one lint error. Otherwise looks good to me

cyyever Add type annotations and fix some lint warnings in Python code
0dcf00bb
cyyever Update onnx/gen_proto.py
75d36461
cyyever Update onnx/hub.py
1bf81014
cyyever cyyever force pushed from 949efab1 to 1bf81014 214 days ago
cyyever Add back ruff suppression
165a6dbe
justinchuby justinchuby merged f615b26d into main 214 days ago
cyyever cyyever deleted the pylint branch 210 days ago

Login to write a write a comment.

Login via GitHub

Assignees
No one assigned
Labels
Milestone