Skip to content

Commit

Permalink
Merge pull request #21 from dangle/use-default-values
Browse files Browse the repository at this point in the history
Fix retrieving values that are not in vars.
  • Loading branch information
dangle authored Oct 11, 2018
2 parents 62afa5f + fd08ee0 commit c16f73d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ universal = 1

[flake8]
ignore =
D202,
D203,
F403,
F405,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
],
license="MIT",
packages=find_packages(exclude=["tests", "docs"]),
install_requires=["pathlib2", "typingplus >= 2.2.1, < 3"],
install_requires=["pathlib2", "typingplus >= 2.2.2, < 3"],
setup_requires=["pytest-runner", "setuptools_scm"],
tests_require=["pytest >= 3.2"],
classifiers=[
Expand Down
10 changes: 10 additions & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ class X(typet.Object):
assert x.x == "5"


def test_object_with_default():
"""Test that Object uses a default value."""

class X(typet.Object):
x = 5 # type: Optional[int]

x = X()
assert x.x == 5


def test_object_comments():
"""Simple test to verify basic Object functionality with comment hints."""

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ commands =
py{27,34,35,py,py3}: py.test --cov=typet --basetemp={envtmpdir} --ignore=tests/py36 {posargs}
py{36}: py.test --cov=typet --basetemp={envtmpdir} {posargs}
- coveralls
pep257 setup.py typet tests
pep257 setup.py typet
flake8 setup.py typet
pylint setup.py typet
py{34,35,36}: - mypy --config=setup.cfg setup.py typet
2 changes: 1 addition & 1 deletion typet/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _fget(self):
# type: (...) -> Any
"""Get attribute from self without revealing the private name."""
try:
return vars(self)[private_attr]
return getattr(self, private_attr)
except AttributeError:
raise AttributeError(
"'{}' object has no attribute '{}'".format(
Expand Down

0 comments on commit c16f73d

Please sign in to comment.