rope.refactor.occurrences ========================= .. py:module:: rope.refactor.occurrences .. autoapi-nested-parse:: Find occurrences of a name in a project. This module consists of a `Finder` that finds all occurrences of a name in a project. The `Finder.find_occurrences()` method is a generator that yields `Occurrence` instances for each occurrence of the name. To create a `Finder` object, use the `create_finder()` function: finder = occurrences.create_finder(project, 'foo', pyname) for occurrence in finder.find_occurrences(): pass It's possible to filter the occurrences. They can be specified when calling the `create_finder()` function. * `only_calls`: If True, return only those instances where the name is a function that's being called. * `imports`: If False, don't return instances that are in import statements. * `unsure`: If a predicate function, return instances where we don't know what the name references. It also filters based on the predicate function. * `docs`: If True, it will search for occurrences in regions normally ignored. E.g., strings and comments. * `in_hierarchy`: If True, it will find occurrences if the name is in the class's hierarchy. * `instance`: Used only when you want implicit interfaces to be considered. * `keywords`: If False, don't return instances that are the names of keyword arguments Classes ------- .. autoapisummary:: rope.refactor.occurrences.Finder rope.refactor.occurrences.Occurrence rope.refactor.occurrences.PyNameFilter rope.refactor.occurrences.InHierarchyFilter rope.refactor.occurrences.UnsureFilter rope.refactor.occurrences.NoImportsFilter rope.refactor.occurrences.CallsFilter rope.refactor.occurrences.NoKeywordsFilter Functions --------- .. autoapisummary:: rope.refactor.occurrences.create_finder rope.refactor.occurrences.same_pyname rope.refactor.occurrences.unsure_pyname Module Contents --------------- .. py:class:: Finder(project, name, filters=None, docs=False) For finding occurrences of a name The constructor takes a `filters` argument. It should be a list of functions that take a single argument. For each possible occurrence, these functions are called in order with the an instance of `Occurrence`: * If it returns `None` other filters are tried. * If it returns `True`, the occurrence will be a match. * If it returns `False`, the occurrence will be skipped. * If all of the filters return `None`, it is skipped also. .. py:attribute:: project .. py:attribute:: name .. py:attribute:: docs :value: False .. py:attribute:: filters :value: None .. py:method:: find_occurrences(resource=None, pymodule=None) Generate `Occurrence` instances .. py:function:: create_finder(project, name, pyname, only_calls=False, imports=True, unsure=None, docs=False, instance=None, in_hierarchy=False, keywords=True) A factory for `Finder` Based on the arguments it creates a list of filters. `instance` argument is needed only when you want implicit interfaces to be considered. .. py:class:: Occurrence(tools, offset) .. py:attribute:: tools .. py:attribute:: offset .. py:attribute:: resource .. py:method:: get_word_range() .. py:method:: get_primary_range() .. py:method:: get_pyname() .. py:method:: get_primary_and_pyname() .. py:method:: is_in_import_statement() .. py:method:: is_called() .. py:method:: is_defined() .. py:method:: is_a_fixed_primary() .. py:method:: is_written() .. py:method:: is_unsure() .. py:method:: is_function_keyword_parameter() .. py:property:: lineno .. py:function:: same_pyname(expected, pyname) Check whether `expected` and `pyname` are the same .. py:function:: unsure_pyname(pyname, unbound=True) Return `True` if we don't know what this name references .. py:class:: PyNameFilter(pyname) For finding occurrences of a name. .. py:attribute:: pyname .. py:class:: InHierarchyFilter(pyname, implementations_only=False) Finds the occurrence if the name is in the class's hierarchy. .. py:attribute:: pyname .. py:attribute:: impl_only :value: False .. py:attribute:: pyclass .. py:class:: UnsureFilter(unsure) Occurrences where we don't knoow what the name references. .. py:attribute:: unsure .. py:class:: NoImportsFilter Don't include import statements as occurrences. .. py:class:: CallsFilter Filter out non-call occurrences. .. py:class:: NoKeywordsFilter Filter out keyword parameters.