Skip to content

Cleanup _get_enum_from_fn implementation in _api.py #8847

@GdoongMathew

Description

@GdoongMathew

🚀 The feature

In the current _get_enum_from_fn implementation, there are two things that can be refined.

  1. https://github.com/pytorch/vision/blob/main/torchvision/models/_api.py#L167-L171, signature function was called twice, but I think it only needs one call.
def _get_enum_from_fn(fn: Callable) -> Type[WeightsEnum]:
    sig = signature(fn)
    if "weights" not in sig.parameters:
        raise ValueError("The method is missing the 'weights' argument.")

    ann = sig.parameters["weights"].annotation    # <-- here
  1. resolve the TODO at line https://github.com/pytorch/vision/blob/main/torchvision/models/_api.py#L177, since torch already removed its support from py3.8, there should be no risk making that modification.

Motivation, pitch

Just saw this and think it'd be helpful?

Alternatives

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions