Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hinting function params, function return value, class attribute using function/class docstrings or PEP-0484 comments. #133

Closed
wants to merge 103 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
9a35259
Hinting the type using docstring of functions
emacsway Dec 31, 2015
b303600
Support for hierarchical tree (Interface) when Hinting the type using…
emacsway Jan 1, 2016
4790e49
Hinting the return type using docstring of functions
emacsway Jan 1, 2016
1cfe36a
Fixed params order and param names in type hinting for function args,…
emacsway Jan 1, 2016
b40b77d
Fixed bug related to cache in rope/base/pyobjects.py(118)get_unknown()
emacsway Jan 1, 2016
4d36f68
Removed redundant _handle_nonfirst_parameters()
emacsway Jan 1, 2016
e6e2f32
Be sure, that variable is not None, to be completely independent of t…
emacsway Jan 1, 2016
d0fd51b
Hinting the attribute type using docstring of class
emacsway Jan 2, 2016
6da5e53
Added docs about type hinting using docstring
emacsway Jan 2, 2016
a1289d2
Added test for hinting type of param
emacsway Jan 2, 2016
ddfded3
Added tests for hinting type of return type and attribute
emacsway Jan 2, 2016
c7da9b9
fixed minor bug in regular expression for Sphinx docstring
emacsway Jan 2, 2016
e650b66
Hinting class attribute defined by NotImplemented or None
emacsway Jan 2, 2016
b924f14
Hinting class attribute defined by NotImplemented or None in constructor
emacsway Jan 2, 2016
e9f02ca
Improved docs, comment for type hinting of attribute
emacsway Jan 2, 2016
2011d4e
fix comment (link to type hinting in pycharm)
emacsway Jan 2, 2016
15e6a97
Fixed bug Python: AttributeError: 'PyObject' object has no attribute …
emacsway Jan 3, 2016
8645f2a
Fixed test for hinting the return type using docstring of interface
emacsway Jan 5, 2016
692549a
Type hints using PEP 0484 comments
emacsway Jan 5, 2016
2a9ed45
Type hints using PEP 0484 comments, added more tests
emacsway Jan 5, 2016
b0a0872
Type hinting: support for expressions returned unknown object
emacsway Jan 5, 2016
99edcf2
Docs for type hints using type comments PEP 0484
emacsway Jan 5, 2016
229d2c7
fixed docs: type hints using type comments of PEP 0484 supported in l…
emacsway Jan 5, 2016
957d63f
fix minor typo
emacsway Jan 5, 2016
6b04a0b
Py3k PyFunction.get_param_names()
emacsway Jan 5, 2016
9204b67
Py3k for _ClassVisitor._FunctionDef(). Now type hinting works in pyth…
emacsway Jan 5, 2016
d67ae68
Removed useless restriction (limited by constructor) in class attribu…
emacsway Jan 7, 2016
e467d3e
Fixed two bugs in PY3
emacsway Jan 9, 2016
04ab99c
minor clean useless variables
emacsway Jan 9, 2016
b3e5ce7
much more Py3k. Currently only failures=50, errors=43
emacsway Jan 9, 2016
7141d84
Py3k: Fixed (partialy) print statement. Currently failures=50, errors=40
emacsway Jan 9, 2016
8e1043e
Python3 compatibility. Now left only (failures=50, errors=22)
emacsway Jan 28, 2016
1b772d0
removed PY2 print where it's not required
emacsway Jan 28, 2016
9927d78
Python3 compatibility. Print statement. Now left only (failures=50, e…
emacsway Jan 29, 2016
703402e
Merge branch 'master' of https://github.com/emacsway/rope
sergeyglazyrindev Jan 29, 2016
89959f5
mostly fixed way how to get param name of the functions, etc
sergeyglazyrindev Jan 30, 2016
ae2f488
fixed unknown param type passed for python2
sergeyglazyrindev Jan 30, 2016
352d1e4
reverted changes back
sergeyglazyrindev Jan 30, 2016
f5483b6
fixed try..except..finally for py3, fixed stdlib issue for py3
sergeyglazyrindev Jan 30, 2016
80b0815
fixed bunch of issues with python 3
sergeyglazyrindev Jan 30, 2016
c971b94
fixed one test case in builtins
sergeyglazyrindev Jan 30, 2016
269a4e1
proper way how to get a path to python standart lib
sergeyglazyrindev Jan 30, 2016
c943726
some improvements and fixed way how we execute files on python3
sergeyglazyrindev Jan 30, 2016
1ea5342
fixed problem with python2
sergeyglazyrindev Jan 30, 2016
c7c3583
fixed with optionalvars for py3
sergeyglazyrindev Jan 30, 2016
1723d4e
fixed style of exception for python3
sergeyglazyrindev Jan 30, 2016
a786cde
fixed more tests for py3
sergeyglazyrindev Jan 30, 2016
008d49e
fixed tests for python2
sergeyglazyrindev Jan 30, 2016
49aaf52
fixed tests for python 3
sergeyglazyrindev Jan 30, 2016
e5c98ee
skip tests in python3 for python statement
sergeyglazyrindev Jan 30, 2016
c06154f
reusing testutils -> support already existed utils in project
sergeyglazyrindev Jan 30, 2016
b7933ec
skip some tests for python3 because of incompatible syntax
sergeyglazyrindev Jan 30, 2016
6206884
fixed try..catch test for py3
sergeyglazyrindev Jan 30, 2016
dd2bf38
not sure about these changes, but let's figure it out later @fixme
sergeyglazyrindev Jan 30, 2016
188e64d
added @todos and fixed problems in extract module
sergeyglazyrindev Jan 31, 2016
f75796b
fixed way how we walk through excepthandler for versions > python2.7
sergeyglazyrindev Jan 31, 2016
632372b
fixed problem with unordered sets and order of variables in function …
sergeyglazyrindev Jan 31, 2016
0925b7d
Merge remote-tracking branch 'source/py3_migration' into py3k
emacsway Feb 1, 2016
9cf18aa
Py3k: fixed test_dict_keys_and_dynamicoi(). Currently failures=21 in …
emacsway Feb 3, 2016
5af9d70
Py3k Added support of NameConstant in patched ast. Currently failures=5
emacsway Feb 3, 2016
4bb6681
Py3k fixed vararg, kwarg in patchedast, now failures=2
emacsway Feb 3, 2016
bb6a0d3
added contributors and small things
sergeyglazyrindev Feb 3, 2016
6050d74
rope.comp -> rope.base.utils.pycompat
emacsway Feb 3, 2016
37d9cfc
Merge branch 'py3k' of https://github.com/emacsway/rope into py3_migr…
sergeyglazyrindev Feb 4, 2016
bc8f684
minor fix for python3
sergeyglazyrindev Feb 4, 2016
9c68340
Revert "minor fix for python3"
sergeyglazyrindev Feb 5, 2016
3b3f2ac
fixed problem with __getslice__ in rope
sergeyglazyrindev Feb 7, 2016
4824404
Merge remote-tracking branch 'remotes/source/py3_migration' into py3k
emacsway Feb 8, 2016
ba72727
fixed issue with doubled __locals__ in Class declaration
sergeyglazyrindev Feb 12, 2016
9363b23
fixed issue with doubled __locals__ in Class declaration
sergeyglazyrindev Feb 12, 2016
d6b7690
fixed issue with evaluating excepthandler
sergeyglazyrindev Feb 12, 2016
6ce97cc
moved ordered_set to datastructures
sergeyglazyrindev Feb 12, 2016
4770420
Merge remote-tracking branch 'sergey/py3_migration' into py3k
emacsway Feb 12, 2016
969da2d
self.assertEquals() -> self.assertEqual()
emacsway Feb 13, 2016
e85797c
Fixed Py3k for nested with statement
emacsway Feb 13, 2016
26a0c74
Merge branch 'py3_migration'
sergeyglazyrindev Feb 14, 2016
70480f9
changed url to repo
sergeyglazyrindev Feb 14, 2016
4551d62
changed url to repo
sergeyglazyrindev Feb 14, 2016
689c001
fixed rst doc
sergeyglazyrindev Feb 14, 2016
c26b9ff
removed mailing lists - later we add another way how to discuss ideas
sergeyglazyrindev Feb 14, 2016
888e099
List supports slice now
emacsway Feb 14, 2016
1c37e32
TODO: add slice support in Tuple
emacsway Feb 14, 2016
1898a64
Temporary revert "self.assertEquals() -> self.assertEqual()" for review
emacsway Feb 14, 2016
c046f60
Merge remote-tracking branch 'origin/py3k'
sergeyglazyrindev Feb 14, 2016
a1db15e
code cleanup -added @todo
sergeyglazyrindev Feb 14, 2016
51e84c8
proper fix for patched ast except handler
sergeyglazyrindev Feb 14, 2016
968084f
fixes to travis yml
sergeyglazyrindev Feb 14, 2016
bd03b7f
Merge remote-tracking branch 'sergey/master' into py3k
emacsway Feb 14, 2016
945bdf3
fixed way how we get path to stdlib
sergeyglazyrindev Feb 14, 2016
aa29337
fixed problem for dlls
sergeyglazyrindev Feb 14, 2016
b867096
minor fix
sergeyglazyrindev Feb 14, 2016
1a7c499
ugly way how to debug travis test
sergeyglazyrindev Feb 14, 2016
e6ba06f
proper fix how to get correct names of the standard modules
sergeyglazyrindev Feb 14, 2016
070225a
remove debug
sergeyglazyrindev Feb 14, 2016
244e032
minor fixes
sergeyglazyrindev Feb 14, 2016
1cb6c26
minor fix
sergeyglazyrindev Feb 14, 2016
c7bbc9a
updated image which shows if tests passed on travis
sergeyglazyrindev Feb 14, 2016
42dccb7
removed @todo comment
sergeyglazyrindev Feb 14, 2016
47139c3
Merge remote-tracking branch 'sergey/master' into py3k
emacsway Feb 14, 2016
fddc128
Merge branch 'py3k'
emacsway Feb 14, 2016
3619997
added source of the orderedset
sergeyglazyrindev Feb 14, 2016
8a0260b
100% tests are passed in Python 3.3, 3.4. So, we can declare that Pyt…
emacsway Feb 15, 2016
2fdc658
Merge remote-tracking branch 'sergey/master'
emacsway Feb 15, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 0 additions & 5 deletions .travis.yml
@@ -1,7 +1,6 @@
language: python
sudo: false
python:
- "2.6"
- "2.7"
- "pypy"
- "3.3"
Expand All @@ -11,8 +10,4 @@ matrix:
allow_failures:
- python: "pypy"
- python: "pypy3"
- python: "3.3"
- python: "3.4"
before_script:
- '[ "${TRAVIS_PYTHON_VERSION}" = "2.6" ] && travis_retry pip install unittest2 || /bin/true'
script: python setup.py test
4 changes: 2 additions & 2 deletions CONTRIBUTORS
Expand Up @@ -2,8 +2,6 @@
Rope Contributors
===================

See Mercurial logs and the mailing list for details.

* Alexander Solovyov <piranha@piranha.org.ua>
* Sebastjan Trepca <trepca@gmail.com>
* MATSUI Tetsushi <mft@users.sf.net>
Expand All @@ -12,3 +10,5 @@ See Mercurial logs and the mailing list for details.
* Orestis Markou <orestis@gmail.com>
* Ronny Pfannschmidt <ronny.pfannschmidt@gmail.com>
* Anton Gritsay <general@angri.ru>
* Ivan Zakrevsky <ivzak@yandex.ru>
* Sergey Glazyrin <sergey.glazyrin.dev@gmail.com>
18 changes: 10 additions & 8 deletions README.rst
@@ -1,5 +1,5 @@

.. _GitHub python-rope / rope: https://github.com/python-rope/rope
.. _GitHub python-rope / rope: https://github.com/sergeyglazyrindev/rope


========================================
Expand All @@ -11,15 +11,18 @@ Overview
========

`Rope`_ is a python refactoring library.
`Official Rope`_ originally was written by @aligrudi and a long time was supported by @mcepl.
We hope to give this library fresh breath and new life.

.. _`rope`: https://github.com/python-rope/rope
.. _`rope`: https://github.com/sergeyglazyrindev/rope
.. _`Official Rope`: https://github.com/python-rope/rope


New Features
============

* Under new management! Matěj Cepl <mcepl@cepl.eu> takes it hesitantly
over
* Right now Ivan Zakrevsky and Sergey Glazyrin as emacs fans are
working to give the library a new life and support at the same time in a roper package python versions > 2.7
* Merged all availables pull requests and patches to the main codebase
* Tests are green again

Expand All @@ -40,10 +43,9 @@ you open a project).
Bug Reports
===========

Send your bug reports and feature requests to `rope-dev (at)
googlegroups.com`_.
Please create issues or enhancements on github `Issues`_ page.

.. _`rope-dev (at) googlegroups.com`: http://groups.google.com/group/rope-dev
.. _`Issues`: https://github.com/sergeyglazyrindev/rope/issues


License
Expand All @@ -59,5 +61,5 @@ Have a look at `COPYING`_ for more information.
.. _`docs/library.rst`: docs/library.html
.. _`COPYING`: COPYING

.. image:: https://secure.travis-ci.org/python-rope/rope.png
.. image:: https://secure.travis-ci.org/sergeyglazyrindev/rope.png
:alt: Build Status
28 changes: 7 additions & 21 deletions docs/contributing.rst
Expand Up @@ -14,22 +14,15 @@ welcome to!
How to Help Rope?
=================

Rope's mailing list is `rope-dev (at) googlegroups.com`_. Click the
"Join group to post" button to subscribe. Then:
Look into `Issues`_ page and check if you can fix/help/suggest how to fix any issue/enhancement.

* Use rope
* Send bug reports and request features
* Submit patches for bugs or new features
* Discuss your ideas

.. _`rope-dev (at) googlegroups.com`: http://groups.google.com/group/rope-dev
.. _`Issues`: https://github.com/sergeyglazyrindev/rope/issues


Wish List
=========

You are welcome to send your patches to the `rope-dev (at)
googlegroups.com`_ mailing list. Here is a list of suggestions.
You are welcome to send your patches to this repository Issues page.

Issues
------
Expand All @@ -38,16 +31,10 @@ The `dev/issues.rst`_ file is actually the main rope todo file. There
is a section called "unresolved issues"; it contains almost every kind
of task. Most of them need some thought or discussion. Pickup
whichever you are most interested in. If you have ideas or questions
about them, don't hesitate to discuss it in the mailing list.
about them, please create corresponding issue and we can discuss enhancements, etc

.. _`dev/issues.rst`: dev/issues.rst

Getting Ready For Python 3.0
----------------------------

Checkout http://bitbucket.org/agr/rope_py3k Mercurial_ repository.
Contributions are welcome.

Write Plugins For Other IDEs
----------------------------

Expand Down Expand Up @@ -78,8 +65,7 @@ more information.
Source Repository
=================

Rope uses GitHub_. The repository exists at
`https://github.com/python-rope/rope`_.
Rope uses GitHub_. The repository exists at https://github.com/sergeyglazyrindev/rope.


Submitting patches
Expand All @@ -99,9 +85,9 @@ Sending Patches
---------------

Follow the instructions on GitHub_ on how to setup Git and fork the
`python-rope/rope`_ repository. Once your changes are ready, send a
`sergeyglazyrindev/rope`_ repository. Once your changes are ready, send a
`pull request`_ for review.

.. _GitHub: http://github.com/
.. _`python-rope/rope`: https://github.com/python-rope/rope
.. _`sergeyglazyrindev/rope`: https://github.com/sergeyglazyrindev/rope
.. _`pull request`: https://help.github.com/articles/using-pull-requests
95 changes: 93 additions & 2 deletions docs/overview.rst
Expand Up @@ -737,8 +737,7 @@ examples. After this example you might like to have a look at:
default wildcard supports.

Finally, restructurings can be improved in many ways (for instance
adding new wildcards). You might like to discuss your ideas in the
mailing list.
adding new wildcards).


Example 1
Expand Down Expand Up @@ -1209,6 +1208,98 @@ Rope uses this feature by default but you can disable it by editing
``config.py``.


Type Hinting
------------

Currently supported type hinting for:

- function parameter type, using function doctring (:type or @type)
- function return type, using function doctring (:rtype or @rtype)
- class attribute type, using class docstring (:type or @type). Attribute should by set to None or NotImplemented in class or constructor of class.
- any assignment, using type comments of PEP 0484 (in limited form).

If rope cannot detect the type of a function argument correctly (due to the
dynamic nature of Python), you can help it by hinting the type using
one of the following docstring syntax styles.


**Sphinx style**

http://sphinx-doc.org/domains.html#info-field-lists

::

def myfunction(node, foo):
"""Do something with a ``node``.

:type node: ProgramNode
:param str foo: foo parameter description

"""
node.| # complete here


**Epydoc**

http://epydoc.sourceforge.net/manual-fields.html

::

def myfunction(node):
"""Do something with a ``node``.

@type node: ProgramNode

"""
node.| # complete here


**Numpydoc**

https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt

In order to support the numpydoc format, you need to install the `numpydoc
<https://pypi.python.org/pypi/numpydoc>`__ package.

::

def foo(var1, var2, long_var_name='hi'):
r"""A one-line summary that does not use variable names or the
function name.

...

Parameters
----------
var1 : array_like
Array_like means all those objects -- lists, nested lists,
etc. -- that can be converted to an array. We can also
refer to variables like `var1`.
var2 : int
The type above can either refer to an actual Python type
(e.g. ``int``), or describe the type of the variable in more
detail, e.g. ``(N,) ndarray`` or ``array_like``.
long_variable_name : {'hi', 'ho'}, optional
Choices in brackets, default first when optional.

...

"""
var2.| # complete here


**PEP 0484**

https://www.python.org/dev/peps/pep-0484/#type-comments

::

class Sample(object):
def __init__(self):
self.x = None # type: random.Random
self.x.| # complete here


Custom Source Folders
=====================

Expand Down
1 change: 1 addition & 0 deletions docs/rope.rst
Expand Up @@ -44,6 +44,7 @@ Features implemented so far:
* Static and dynamic object analysis
* Handling built-in container types
* Saving object information on disk and validating them
* Type hints using docstring or type comments PEP 0484

For more information see `overview.rst`_.

Expand Down
3 changes: 3 additions & 0 deletions rope/base/astutils.py
Expand Up @@ -40,6 +40,9 @@ def _added(self, node, levels):
def _Name(self, node):
self._add_node(node)

def _ExceptHandler(self, node):
self.names.append((node.name, []))

def _Tuple(self, node):
new_levels = []
if self.levels is not None:
Expand Down
21 changes: 13 additions & 8 deletions rope/base/builtins.py
Expand Up @@ -6,7 +6,8 @@
raw_input = input

import rope.base.evaluate
from rope.base import pynames, pyobjects, arguments, utils, ast
from rope.base.utils import pycompat
from rope.base import pynames, pyobjects, arguments, utils


class BuiltinModule(pyobjects.AbstractModule):
Expand Down Expand Up @@ -271,7 +272,7 @@ def __init__(self, holding=None):
collector('__getitem__', function=self._list_get)
collector('pop', function=self._list_get)
try:
collector('__getslice__', function=self._self_get)
collector('__getslice__', function=self._list_get)
except AttributeError:
pass

Expand All @@ -297,6 +298,10 @@ def _self_set(self, context):

def _list_get(self, context):
if self.holding is not None:
args = context.get_arguments(['self', 'key'])
if (len(args) > 1 and args[1] is not None and
args[1].get_type() == builtins['slice'].get_object()):
return get_list(self.holding)
return self.holding
return context.get_per_name()

Expand Down Expand Up @@ -414,7 +419,7 @@ def __init__(self, *objects):
if objects:
first = objects[0]
attributes = {
'__getitem__': BuiltinName(BuiltinFunction(first)),
'__getitem__': BuiltinName(BuiltinFunction(first)), # TODO: add slice support
'__getslice__':
BuiltinName(BuiltinFunction(pyobjects.PyObject(self))),
'__new__': BuiltinName(BuiltinFunction(function=self._new_tuple)),
Expand Down Expand Up @@ -656,12 +661,12 @@ def get_name(self):
return 'lambda'

def get_param_names(self, special_args=True):
result = [node.id for node in self.arguments.args
if isinstance(node, ast.Name)]
result = [pycompat.get_ast_arg_arg(node) for node in self.arguments.args
if isinstance(node, pycompat.ast_arg_type)]
if self.arguments.vararg:
result.append('*' + self.arguments.vararg)
result.append('*' + pycompat.get_ast_arg_arg(self.arguments.vararg))
if self.arguments.kwarg:
result.append('**' + self.arguments.kwarg)
result.append('**' + pycompat.get_ast_arg_arg(self.arguments.kwarg))
return result

@property
Expand Down Expand Up @@ -801,4 +806,4 @@ def _input_function(args):
builtin=raw_input)),
}

builtins = BuiltinModule('__builtin__', initial=_initial_builtins)
builtins = BuiltinModule(pycompat.builtins.__name__, initial=_initial_builtins)
7 changes: 6 additions & 1 deletion rope/base/evaluate.py
Expand Up @@ -2,6 +2,7 @@
import rope.base.pynames
import rope.base.pyobjects
from rope.base import ast, astutils, exceptions, pyobjects, arguments, worder
from rope.base.utils import pycompat


BadIdentifierError = exceptions.BadIdentifierError
Expand Down Expand Up @@ -290,7 +291,11 @@ def _Subscript(self, node):
self._call_function(node.value, '__getitem__',
[node.slice.value])
elif isinstance(node.slice, ast.Slice):
self._call_function(node.value, '__getslice__')
self._call_function(node.value, '__getitem__',
[node.slice])

def _Slice(self, node):
self.result = self._get_builtin_name('slice')

def _call_function(self, node, function_name, other_args=None):
pyname = eval_node(self.scope, node)
Expand Down