Skip to content

Many uncalled functions #2279

Closed
Closed

Description

@elazarg

I wrote a small script that looks for defs that are not mentioned elsewhere. Nothing fancy or clever.

Running it on mypy/*.py mypy/test/*.py yields 24 unused functions (output below). I have tried removing all of them except the 4 functions from mypy/test/data.py, and the tests pass swiftly. After removing some of them, the script finds some more.

I guess not everything is unnecessary (especially messages.py), but my guess is most of them are. And those that are needed are untested.

mypy/nodes.py :
        get_var_or_getter
        is_constructor
        has_writable_member
        all_base_classes
        get_var_or_setter
mypy/checker.py :
        check_type_equivalency
        wrap_generic_type
mypy/messages.py :
        incomplete_type_var_match
        incompatible_value_count_in_assignment
        type_expected_as_right_operand_of_is
        incompatible_array_item_type
        invalid_reverse_operator_signature
        function_variants_overlap
        type_incompatible_with_supertype
        not_implemented
        reverse_operator_method_with_any_arg_must_return_any
        boolean_return_value_expected
        incomplete_conversion_specifier_format
mypy/build.py :
        effective_path
mypy/semanal.py :
        is_instance_type
        add_var
mypy/treetransform.py :
        optional_types
        duplicate_inits
mypy/parse.py :
        expect_colon_and_break
mypy/test/data.py :
        reportinfo
        repr_failure
        runtest
        teardown
mypy/errors.py :
        mark_file_ignored_lines_used
        pop_import_context
        push_import_context
mypy/checkexpr.py :
        apply_generic_arguments2
        has_non_method
        is_boolean

[Edit: I have added another script there. It is more sophisticated and it finds more unused functions (41), but I did not verify its results in this project so it might have more false positives]

Activity

  1. elazarg commented on Oct 18, 2016

    @elazarg
    ContributorAuthor

    @gvanrossum I thought you might like this

  2. gvanrossum commented on Oct 18, 2016

    @gvanrossum
    Member
  3. elazarg commented on Oct 18, 2016

    @elazarg
    ContributorAuthor

    The script only misses dynamically-constructed names, which mypy does not track anyway and which this project tries to avoid. mypy can find more uncalled function, but it can't avoid false positives (of which, to my knowledge, currently there are none; I admit that avoiding test_* is hardcoded in the script).

  4. gvanrossum commented on Oct 20, 2016

    @gvanrossum
    Member

    FWIW, N small PRs that clean up one issue each are much quicker to review than one large PR that cleans up those same N issues.

  5. added this to the milestone on Oct 20, 2016
  6. elazarg commented on Oct 25, 2016

    @elazarg
    ContributorAuthor

    Looks like the script has amazingly small number of false positives, compared to more sophisticated ast-based versions such as vulture and my own. Yet it is effective. I find it interesting.

    The script also warns about the following:

    mypy/test/helpers.py: Unused function assert_string_arrays_equal_wildcards
    mypy/util.py: Unused function array_repr
    runtests.py: Unused function add_python2
    runtests.py: Unused function add_mypy_string
    runtests.py: Unused function add_python
    

    But I am a bit hesitant about removing them.

  7. gvanrossum commented on Oct 25, 2016

    @gvanrossum
    Member
  8. JukkaL commented on Oct 25, 2016

    @JukkaL
    Collaborator

    Much of the codebase was actually written in Alore, which was an even simpler language than the old mypy language. I translated the Alore codebase to the mypy language using a tool, and this resulted in some interesting style issues that you might still find in some parts of the codebase, though most of those have been cleaned up by now.

  9. removed this from the milestone on Mar 29, 2017
  10. elazarg commented on Jun 11, 2018

    @elazarg
    ContributorAuthor

    I still use uncalled from time to time; it reveals some unused functions now and then, but this is no longer an real issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions