Skip to content

Commit

Permalink
apply class-level decorators to all consumer methods including inheri…
Browse files Browse the repository at this point in the history
…ted, fixes prkumar#119
  • Loading branch information
daa committed Jan 22, 2019
1 parent 2550265 commit 6bc457f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
6 changes: 3 additions & 3 deletions tests/unit/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ class Parent(interfaces.Consumer):
class Child(Parent):
pass

# Method annotation should not decorate RequestDefinitionBuilder
# attribute of parent class (e.g., `Parent.builder`).
# Method annotation should decorate RequestDefinitionBuilder attribute
# of parent class (e.g., `Parent.builder`).
method_annotation(Child)
builder = request_definition_builder.method_handler_builder
assert not builder.add_annotation.called
assert builder.add_annotation.called


# TODO: Refactor test cases for method annotations into test case class.
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class Child(Parent):
other_builder = request_definition_builder

assert dict(helpers.get_api_definitions(Child)) == {
"other_builder": request_definition_builder
"builder": request_definition_builder,
"other_builder": request_definition_builder,
}


Expand Down
6 changes: 2 additions & 4 deletions uplink/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ def get_api_definitions(service):
class.
Note:
Only attributes defined directly on the class are considered. In
other words, inherited `RequestDefinitionBuilder` attributes
are ignored.
All attributes are considered, not only defined directly on the class.
Args:
service: A class object.
Expand All @@ -28,7 +26,7 @@ def get_api_definitions(service):
# report in Python issue tracker). Directly invoking `getattr` to
# force Python's attribute lookup protocol is a decent workaround to
# ensure parity:
class_attributes = ((k, getattr(service, k)) for k in service.__dict__)
class_attributes = ((k, getattr(service, k)) for k in dir(service))

is_definition = interfaces.RequestDefinitionBuilder.__instancecheck__
return [(k, v) for k, v in class_attributes if is_definition(v)]
Expand Down

0 comments on commit 6bc457f

Please sign in to comment.