Skip to content

Commit

Permalink
Merge pull request #641 from edreamleo/ekr-ropemode-docstring
Browse files Browse the repository at this point in the history
PR: Add type annotations for rope.contrib.generate.create_generate()
  • Loading branch information
lieryan committed Jan 5, 2023
2 parents 5989d60 + 2fc4bb8 commit d24294f
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions rope/contrib/generate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from rope.base import (
change,
codeanalyze,
Expand All @@ -10,13 +14,32 @@
)
from rope.refactor import functionutils, importutils, sourceutils, suites

if TYPE_CHECKING:
from typing import Literal, Optional

def create_generate(kind, project, resource, offset, goal_resource=None):
"""A factory for creating `Generate` objects
from rope.base.project import Project
from rope.base.resources import Resource

GenerateKind = Literal[
"variable",
"function",
"class",
"module",
"package",
]

`kind` can be 'variable', 'function', 'class', 'module' or
'package'.

def create_generate(
kind: GenerateKind,
project: Project,
resource: Resource,
offset: int,
goal_resource: Optional[Resource] = None,
):

"""A factory for creating `Generate` objects
Used in https://github.com/python-rope/ropemode but not in Rope itself.
"""
d = {
"class": GenerateClass,
Expand All @@ -25,7 +48,7 @@ def create_generate(kind, project, resource, offset, goal_resource=None):
"package": GeneratePackage,
"variable": GenerateVariable,
}
generate = d.get(kind)
generate = d[kind]
return generate(project, resource, offset, goal_resource=goal_resource)


Expand Down

0 comments on commit d24294f

Please sign in to comment.