Skip to content

Doesn't report a cached_property #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
oprypin opened this issue Jan 3, 2021 · 5 comments
Closed

Doesn't report a cached_property #86

oprypin opened this issue Jan 3, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@oprypin
Copy link
Member

oprypin commented Jan 3, 2021

foo.py

import functools

import cached_property


class C:
    @property
    def aaa(self):
        """aaa"""

    @functools.cached_property
    def bbb(self):
        """bbb"""

    @cached_property.cached_property
    def ccc(self):
        """ccc"""

Only aaa (the normal property) is reported. Both functools.cached_property and cached_property.cached_property are ignored.

python -m pytkdocs <<<'{"objects":[{"path": "foo.C"}]}' | jq      
{
  "loading_errors": [],
  "parsing_errors": {},
  "objects": [
    {
      "name": "C",
      "path": "foo.C",
      "category": "class",
      "file_path": "/tmp/foo.py",
      "relative_file_path": "tmp/foo.py",
      "properties": [],
      "parent_path": "foo",
      "has_contents": true,
      "docstring": "",
      "docstring_sections": [],
      "source": {},
      "children": {
        "foo.C.aaa": {
          "name": "aaa",
          "path": "foo.C.aaa",
          "category": "attribute",
          "file_path": "/tmp/foo.py",
          "relative_file_path": "tmp/foo.py",
          "properties": [
            "property",
            "readonly"
          ],
          "parent_path": "foo.C",
          "has_contents": true,
          "docstring": "aaa",
          "docstring_sections": [
            {
              "type": "markdown",
              "value": "aaa"
            }
          ],
          "source": {
            "code": "    @property\n    def aaa(self):\n        \"\"\"aaa\"\"\"\n",
            "line_start": 7
          },
          "children": {},
          "attributes": [],
          "methods": [],
          "functions": [],
          "modules": [],
          "classes": [],
          "type": ""
        }
      },
      "attributes": [
        "foo.C.aaa"
      ],
      "methods": [],
      "functions": [],
      "modules": [],
      "classes": []
    }
  ]
}
@pawamoy pawamoy added the bug Something isn't working label Jan 3, 2021
@pawamoy
Copy link
Member

pawamoy commented Feb 7, 2021

Confirmed, thanks for the report @oprypin. I'll investigate 🙂

@yajo
Copy link

yajo commented Feb 7, 2021

I just wanted to mention that this is affecting copier-org/copier#314 too.

@pawamoy
Copy link
Member

pawamoy commented Feb 7, 2021

And I just found why it happens 🙂

Reading https://docs.python.org/3/library/functools.html#functools.cached_property, we see that a cached property does not use the same mechanics of a classic property. Maybe not relevant. But then inspect.unwrap returns the same object (<functools.cached_property at 0x...>), and pytkdocs.loader.ObjectNode.is_property returns False.

I guess we can add a bit of code in that is_property method to support cached_property. Something like:

    def is_property(self) -> bool:
        return isinstance(self.obj, property) or isinstance(self.obj, cached_property)

Let see how the rest of the code behaves with this change. Continuing investigation 🙂

pawamoy added a commit that referenced this issue Feb 9, 2021
@pawamoy
Copy link
Member

pawamoy commented Feb 9, 2021

Just pushed a fix, closing! Please tell me if it works or not!

@pawamoy pawamoy closed this as completed Feb 9, 2021
pawamoy added a commit that referenced this issue Feb 9, 2021
@yajo
Copy link

yajo commented Feb 9, 2021

Yes, it works, thanks!

yajo added a commit to copier-org/copier that referenced this issue Feb 9, 2021
yajo added a commit to copier-org/copier that referenced this issue Feb 9, 2021
* Refactor
* Fix #110.
* Rewrite test_config_exclude, test_config_exclude_overridden and test_config_include. These tests were badly designed, using a monkeypatch that would never happen in the real world, and actually producing false positives. I moved them to test_exclude.py and rewritten to test the what and not the how.
* Fix #214 by removing skip option. Relevant tests use the better skip_if_exists=["**"].
* Remove subdirectory flag from API/CLI. It was confusing and could lead to bad maintenance situations. Fixes #315.
* Remove extra_paths and fix #321
* Remember that you cannot use _copier_conf.src_path as a path now
* use dataclasses
* Create errors module, simplify some tests, fix many others
* Fix some tests, complete EnvOps removal
* Fix #214 and some tests related to it
* Reorder code
* Update docs and imports
* Modularize test_complex_questions
* Interlink worker and questionary a bit better
* Removal of Questionary class, which only had 1 meaningful method that is now merged into Worker to avoid circular dependencies.
* Fix #280 in a simple way: only user answers are type-casted inside API, and CLI transforms all `--data` using YAML always. Predictable.
* Use prereleases correctly.
* Reorder AnswersMap to have a more significative repr.
* Simpler cache for old `Question.get_choices()` method (renamed now).
* fix wrong test
* Fix test_subdirectory
* Fix test_tasks (and remove tests/demo_tasks)
* Fix path filter tests, and move it to test_exclude, where it belongs
* Make test_config pass
* Fix more wrongly designed tests
* Use cached_property backport if needed
* xfail test known to fail on mac
* force posix paths on windows
* Add typing_extensions for python < 3.8
* Sort dependencies in pyproject.toml
* Support python 3.6 str-to-datetime conversion
* Workaround https://bugs.python.org/issue43095
* xfail test_path_filter on windows
* Upgrade mkdocs and other dependencies to fix mkdocstrings/mkdocstrings#222
* Add missing reference docs.
* Add workaround for mkdocstrings/mkdocstrings#209
* Docs.
* Remove validators module
* Add workaround for mkdocstrings/mkdocstrings#225
* Restore docs autorefs as explained in mkdocstrings/mkdocstrings#226 (comment).
* Workaround mkdocstrings/pytkdocs#86
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants