Does not find examples when @property also has a @....setter defined
See original GitHub issueRunning Python 3.8.3 (set up with pyenv), xdoctest 0.12.0 (installed via pip install xdoctest[all]
). In a class, when I have an @property
defined, with a nice docstring, and then also define a setter
, xdoctest does not see the example. Here’s a minimum example:
class Test(object):
@property
def test(self):
"""
Example:
>>> ini = Test()
>>> ini.test
3.14
"""
return 3.14
@test.setter
def test(self, s):
pass
The output I receive when I run xdoctest test_min.py
is:
=====================================
_ _ ___ ____ ____ ___ ____ ____ ___
\/ | \ | | | | |___ [__ |
_/\_ |__/ |__| |___ | |___ ___] |
=====================================
Start doctest_module('xdoctest_min.py')
Listing tests
gathering tests
running 0 test(s)
============
=== in 0.00 seconds ===
If I remove the whole @test.setter
method, the test succeeds properly. Any ideas on what might be going wrong here / what I’m missing?
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Determine if a JavaScript property has a getter or setter ...
I only want to define a getter/setter if there is not already one defined on the property.
Read more >Property getters and setters
Accessor properties are represented by “getter” and “setter” methods. In an object literal they are denoted by get and set :.
Read more >3. Properties vs. Getters and Setters | OOP
The following example shows a class, which has internal attributes, which can't be accessed from outside. These are the private attributes self.
Read more >What to do about setters of a different type than their ...
Consider this code: import typing class A: @property def f(self) -> int: return 1 @f.setter # Possible error for defining a setter that ......
Read more >setter - JavaScript - MDN Web Docs
In JavaScript, a setter can be used to execute a function whenever a specified property is attempted to be changed. Setters are most...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I downgraded pytest-cov in the CI scripts so the release scripts would pass. Xdoctest version 0.13.0 contains this fix and is now on pypi.
The google example is consistent. Its ok to document getters, but you don’t have to. Its also consistent in disallowing (by convention) documentation in setters / deleters. This is likely because those
__doc__
attributes are not top-level accessible in the Python runtime state. (e.g when you doself.__class__.myprop.__doc__
you get the getter’s doc by default, although it is possible to doself.__class__.myprop.fset.__doc__
)I did some digging of my own and came up with this example to disect the exact behavior of properties:
These tests demonstrate how the docstring of the property defaults to that of the getter. So, I’m fairly confident ignoring the setters / deleters is the right approach for consistency with the dynamic parser.