8000 Fix name resolving issues by tristanlatr · Pull Request #663 · twisted/pydoctor · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix name resolving issues #663

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 8000

Merged
merged 47 commits into from
May 28, 2023
Merged

Conversation

tristanlatr
Copy link
Contributor
@tristanlatr tristanlatr commented Nov 17, 2022

Fix issues #661 and #662.

Apply rule "Annotations should always be resolved in the context of the module scope"

@codecov
Copy link
codecov bot commented Nov 17, 2022

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.04 🎉

Comparison is base (f25410d) 92.45% compared to head (38802b5) 92.49%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #663      +/-   ##
==========================================
+ Coverage   92.45%   92.49%   +0.04%     
==========================================
  Files          47       47              
  Lines        8056     8103      +47     
  Branches     1925     1935      +10     
==========================================
+ Hits         7448     7495      +47     
  Misses        354      354              
  Partials      254      254              
Impacted Files Coverage Δ
pydoctor/astbuilder.py 95.99% <100.00%> (+0.02%) ⬆️
pydoctor/epydoc/markup/__init__.py 93.54% <100.00%> (ø)
pydoctor/epydoc/markup/_pyval_repr.py 92.98% <100.00%> (+0.01%) ⬆️
pydoctor/epydoc2stan.py 94.43% <100.00%> (+0.01%) ⬆️
pydoctor/linker.py 90.14% <100.00%> (+2.00%) ⬆️
pydoctor/model.py 94.63% <100.00%> (+0.07%) ⬆️
pydoctor/templatewriter/pages/__init__.py 90.80% <100.00%> (+0.10%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@tristanlatr
Copy link
Contributor Author

Marked as draft until #599 is merged.

@glyph
Copy link
Member
glyph commented Dec 5, 2022

Dropping myself from review until other stuff is merged, conflicts are resolved, etc

@glyph glyph removed their request for review December 5, 2022 23:53
@tristanlatr tristanlatr marked this pull request as ready for review April 21, 2023 01:18
@tristanlatr tristanlatr requested a review from glyph April 21, 2023 03:04
…rds imports in the localNameToFullName mapping as well to know wether they are defined or not.
Copy link
Member
@glyph glyph left a comment

Choose a reason for hiding this comment

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

LGTM. Please fix the couple of coverage gaps before landing though.

Comment on lines 273 to 274
def isNameDefined(self, name:str) -> bool:
raise NotImplementedError(self.isNameDefined)
Copy link
Member

Choose a reason for hiding this comment

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

Should this become an ABC as well, given that this is really an abstractmethod?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it should, but some tests rely on the fact that Documentable can be instantiated standalone... It might be too much refactors to change that.

Copy link
Contributor Author
@tristanlatr tristanlatr May 28, 2023

Choose a reason for hiding this comment

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

Ok, it's more deep that I thought. Since we're not actually using these Documentable classes, but actually dynamically building derived classes in the factory, it actually can't use abc at all, otherwise we're running into the following error:

def add_mixin(self, for_class: str, mixin: Type[Any]) -> None:
        super().add_mixin(for_class, mixin)
    
        # Take care to avoid inconsistent MRO by removing extra model.* classes from the Mixin bases.
        try:
            b = list(mixin.__bases__)
            b.remove(getattr(self.model, for_class))
>           mixin.__bases__ = tuple(b)
E           TypeError: __bases__ assignment: 'ModuleMixin' object layout differs from 'Module'

Please tell me if you have any idea on how to overcome this situation.

In the mean time, I'll merge this PR, thanks.

Edit: I've realized that it's all because I've decided to accept mixin classes that bases the concrete classes for type checking purposes but remove the base class at runtime, and that's why the ABCs are not happy with this situation. The solution would be to stop supporting extending concrete Documentable classes in the mixin. But this would be a major pain for mypy.

Copy link
Contributor Author
@tristanlatr tristanlatr left a comment

Choose a reason for hiding this comment

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

Thanks a lot for your review @glyph, I really appreciate.

Comment on lines 273 to 274
def isNameDefined(self, name:str) -> bool:
raise NotImplementedError(self.isNameDefined)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it should, but some tests rely on the fact that Documentable can be instantiated standalone... It might be too much refactors to change that.

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.

2 participants
0