From 747c2bfa7800cb6aff5bb7373891f275a9dc8543 Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Wed, 12 Nov 2014 21:22:25 +0300 Subject: [PATCH] Snapshot of python-skeletons @ a3175f6 --- python/helpers/python-skeletons/README.md | 66 ++++++++++--------- .../helpers/python-skeletons/__builtin__.py | 6 ++ python/helpers/python-skeletons/builtins.py | 6 ++ .../helpers/python-skeletons/collections.py | 1 + python/helpers/python-skeletons/itertools.py | 12 ++++ .../helpers/python-skeletons/os/__init__.py | 7 +- python/helpers/python-skeletons/sys.py | 9 +++ 7 files changed, 72 insertions(+), 35 deletions(-) create mode 100644 python/helpers/python-skeletons/itertools.py create mode 100644 python/helpers/python-skeletons/sys.py diff --git a/python/helpers/python-skeletons/README.md b/python/helpers/python-skeletons/README.md index ac3af02c6823..446ad39a7a73 100644 --- a/python/helpers/python-skeletons/README.md +++ b/python/helpers/python-skeletons/README.md @@ -64,17 +64,17 @@ Skeletons should respect [PEP-8](http://www.python.org/dev/peps/pep-0008/) and If you need to reference the members of the original module of a skeleton, you should import it explicitly. For example, in a skeleton for the `foo` module: - import foo +```python +import foo +class C(foo.B): + def bar(): + """Do bar and return Bar. - class C(foo.B): - def bar(): - """Do bar and return Bar. - - :rtype: foo.Bar - """ - return foo.Bar() - + :rtype: foo.Bar + """ + return foo.Bar() +``` Modules can be referenced in docstring without explicit imports. The body of a function in a skeleton file should consist of a single `return` @@ -124,36 +124,37 @@ Python 3 function annotations. If you want to create a parameterized class, you should define its parameters in the mock return type of a constructor: - class C(object): - """Some collection C that can contain values of T.""" +```python +class C(object): + """Some collection C that can contain values of T.""" - def __init__(self, value): - """Initialize C. + def __init__(self, value): + """Initialize C. - :type value: T - :rtype: C[T] - """ - pass + :type value: T + :rtype: C[T] + """ + pass - def get(self): - """Return the contained value. - - :rtype: T - """ - pass + def get(self): + """Return the contained value. + :rtype: T + """ + pass +``` ### Versioning The recommended way of checking the version of Python is: - import sys - - - if sys.version_info >= (2, 7) and sys.version_info < (3,): - def from_27_until_30(): - pass +```python +import sys +if sys.version_info >= (2, 7) and sys.version_info < (3,): + def from_27_until_30(): + pass +``` A skeleton should document the most recently released version of a library. Use deprecation warnings for functions that have been removed from the API. @@ -209,9 +210,10 @@ plugin 3.0.1 for IntelliJ still doesn't include this repository). You plugin for IntelliJ installation. If you want to change the skeletons, clone the skeletons GitHub repository into your PyCharm/IntelliJ config directory: - cd - git clone https://github.com/JetBrains/python-skeletons.git - +```bash +cd +git clone https://github.com/JetBrains/python-skeletons.git +``` where `` is: * PyCharm diff --git a/python/helpers/python-skeletons/__builtin__.py b/python/helpers/python-skeletons/__builtin__.py index 0324085cad3d..afa270ba02b3 100644 --- a/python/helpers/python-skeletons/__builtin__.py +++ b/python/helpers/python-skeletons/__builtin__.py @@ -2168,6 +2168,12 @@ class dict(object): """ pass + def __iter__(self): + """ + :rtype: collections.Iterator[T] + """ + pass + def __len__(self): """Return the number of items in the dictionary d. diff --git a/python/helpers/python-skeletons/builtins.py b/python/helpers/python-skeletons/builtins.py index bff1b83c210a..f8595ea63200 100644 --- a/python/helpers/python-skeletons/builtins.py +++ b/python/helpers/python-skeletons/builtins.py @@ -1857,6 +1857,12 @@ class dict(object): """ pass + def __iter__(self): + """ + :rtype: collections.Iterator[T] + """ + pass + def __len__(self): """Return the number of items in the dictionary d. diff --git a/python/helpers/python-skeletons/collections.py b/python/helpers/python-skeletons/collections.py index ec23ec8d8169..4647a8ff7495 100644 --- a/python/helpers/python-skeletons/collections.py +++ b/python/helpers/python-skeletons/collections.py @@ -19,6 +19,7 @@ class Iterator(collections.Iterable): """ pass + if sys.version_info < (3, 0): def next(self): """ :rtype: T diff --git a/python/helpers/python-skeletons/itertools.py b/python/helpers/python-skeletons/itertools.py new file mode 100644 index 000000000000..969e49930607 --- /dev/null +++ b/python/helpers/python-skeletons/itertools.py @@ -0,0 +1,12 @@ +"""Skeleton for 'itertools' stdlib module.""" + +class islice(object): + def __init__(self, iterable, start, stop=None, step=None): + """ + :type iterable: collections.Iterable[T] + :type start: numbers.Integral + :type stop: numbers.Integral | None + :type step: numbers.Integral | None + :rtype: itertools.islice[T] + """ + pass diff --git a/python/helpers/python-skeletons/os/__init__.py b/python/helpers/python-skeletons/os/__init__.py index f7e6844392b2..3d8867d67d98 100644 --- a/python/helpers/python-skeletons/os/__init__.py +++ b/python/helpers/python-skeletons/os/__init__.py @@ -241,10 +241,9 @@ def setreuid(ruid, euid): pass -def setsid(pid): +def setsid(): """Call the system call getsid(). - :type pid: int :rtype: None """ pass @@ -898,11 +897,13 @@ def statvfs(path): pass -def symlink(source, link_name): +def symlink(source, link_name, target_is_directory=False, dir_fd=None): """Create a symbolic link pointing to source named link_name. :type source: bytes | unicode :type link_name: bytes| unicode + :type target_is_directory: bool + :type dir_fd: int | None :rtype: None """ pass diff --git a/python/helpers/python-skeletons/sys.py b/python/helpers/python-skeletons/sys.py new file mode 100644 index 000000000000..03956411c38e --- /dev/null +++ b/python/helpers/python-skeletons/sys.py @@ -0,0 +1,9 @@ +"""Skeleton for 'sys' stdlib module.""" + + +def getsizeof(object, default=None): + """ + :type default: T | None + :rtype: int | T + """ + return 0