Skip to content
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

Document and follow aliases better #414

Draft
wants to merge 44 commits into
base: master
Choose a base branch
from

Conversation

tristanlatr
Copy link
Contributor

@tristanlatr tristanlatr commented Jun 26, 2021

Add aliases to the output and add them in the system with a special kind: ALIAS.

This PR introduces major changes in the manner Documentable.expandName() processes the aliases.
Since we are now creating legit documentable object for every alias, the expandName() has to follow them.

See #313 for details.

Screen Shot 2021-06-26 at 2 33 46 AM

TODO:

  • Refine the checks for variables being flagged as alias:
  • An instance variable should not be flagged as an alias
  • Should a attribute that is overridden be flagged as an alias?
  • Don’t create alias for constants like NotImplemented, simply create a Attribute
  • Ideally use better static analysis to determine if the attribute is assigned only once, in which case it’s considered as an alias, otherwise not.
  • Don’t create Documentables for variables that are not documented, instead create a new object type Alias that is not a documentable. Same for Imports.
  • 'Module.state' should not be flagged as an alias neither because it's actually a variable. But detecting it's usage is hard because we declare it as class variable and used as an instance variable.

by default 2022-06-12 at 9 53 34 PM

@tristanlatr tristanlatr marked this pull request as draft June 26, 2021 06:35
tristanlatr added 2 commits June 26, 2021 03:50
…l alias. An module-level alias must be defined at the top level of the module.
@codecov
Copy link

codecov bot commented Jun 26, 2021

Codecov Report

Attention: 29 lines in your changes are missing coverage. Please review.

Comparison is base (5393bd8) 92.31% compared to head (791da52) 92.20%.
Report is 192 commits behind head on master.

❗ Current head 791da52 differs from pull request most recent head d262d87. Consider uploading reports for the commit d262d87 to get more accurate results

Files Patch % Lines
pydoctor/templatewriter/pages/__init__.py 63.15% 5 Missing and 2 partials ⚠️
pydoctor/names.py 93.18% 3 Missing and 3 partials ⚠️
pydoctor/astbuilder.py 90.56% 2 Missing and 3 partials ⚠️
pydoctor/epydoc2stan.py 28.57% 4 Missing and 1 partial ⚠️
pydoctor/templatewriter/pages/attributechild.py 50.00% 3 Missing and 1 partial ⚠️
pydoctor/model.py 96.42% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #414      +/-   ##
==========================================
- Coverage   92.31%   92.20%   -0.11%     
==========================================
  Files          45       46       +1     
  Lines        7959     8095     +136     
  Branches     1736     1767      +31     
==========================================
+ Hits         7347     7464     +117     
- Misses        356      370      +14     
- Partials      256      261       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

tristanlatr and others added 6 commits June 26, 2021 20:49
…computing it from AST all the time.

Consider variables that are not on the root level as aliases, too. And warns only when they are actually overriden.

Move node2fullname to astutils module.

Delete overridenInCount from ClassPage since it was unused.

Re-export names that are not part of the current system with an alias.

Cleanup expandName() and associated.

Use directly taglink() in format_alias_value() when possible.

Add Documentable.aliases property. This is somewhat working in the tests but not always in real life.

Rename the redirected_from parameter to "indirections".

Speaking of tests, this commit also adds A LOT of new tests for the expandName() method.
@tristanlatr tristanlatr linked an issue Jan 1, 2022 that may be closed by this pull request
@tristanlatr tristanlatr changed the title Aliases Document and follow aliases better May 25, 2022
@tristanlatr
Copy link
Contributor Author

Should undocumented aliases be shown in output ? I current implementation does, maybe we should think about it twice, because it cause create a lot of noise in the docs.

@@ -20,7 +20,7 @@
<t:transparent t:render="functionBody">
Docstring.
</t:transparent>
<t:transparent t:render="constantValue">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be change, i'll revert it to still be "constantValue".

Comment on lines -358 to +381
def one(item: str) -> "Flattenable":
r: List['Flattenable'] = []
for i, item in enumerate(lst):
if i>0:
r.append(', ')
if item in system.allobjects:
return tags.code(epydoc2stan.taglink(system.allobjects[item], page_url))
r.append(tags.code(epydoc2stan.taglink(system.allobjects[item], page_url)))
else:
return item
def commasep(items: Sequence[str]) -> List["Flattenable"]:
r = []
for item in items:
r.append(one(item))
r.append(', ')
del r[-1]
return r
r.append(tags.code(item))
p: List["Flattenable"] = [label]
p.extend(commasep(lst))
p.extend(r)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change necessary ?

Comment on lines +10 to +13
# Dirty hack to work without the typing_extensions dep at runtime.
from collections import defaultdict
from functools import partial
Final = defaultdict(partial(defaultdict, defaultdict))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 'Final' as string instead of doing that.

class ModuleVistor(NodeVisitor):

def __init__(self, builder: 'ASTBuilder', module: model.Module):
super().__init__()
self.builder = builder
self.system = builder.system
self.module = module
self._moduleLevelAssigns: List[str] = []
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like dead code, I'll remove it.

pydoctor/model.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document Documentable.expandName
1 participant