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

Add return type to get_children #2094

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

nickdrozd
Copy link
Contributor

Type of Changes

Type
βœ“ πŸ”¨ Refactoring

Description

Add return annotations for get_children throughout. This reduces the number of warnings with strict Mypy, but it actually increases the number of non-strict warnings due to exposing other errors.

@codecov
Copy link

codecov bot commented Apr 4, 2023

Codecov Report

Merging #2094 (3ff6065) into main (81c6c8f) will not change coverage.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2094   +/-   ##
=======================================
  Coverage   92.77%   92.77%           
=======================================
  Files          94       94           
  Lines       11026    11026           
=======================================
  Hits        10229    10229           
  Misses        797      797           
Flag Coverage Ξ”
linux 92.53% <100.00%> (ΓΈ)
pypy 88.07% <100.00%> (ΓΈ)
windows 92.32% <100.00%> (ΓΈ)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Ξ”
astroid/nodes/node_classes.py 94.97% <100.00%> (ΓΈ)
astroid/nodes/scoped_nodes/scoped_nodes.py 93.07% <100.00%> (ΓΈ)

Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

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

This should be SuccessfulInferenceResult. See get_children of nodes.Dict.

Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

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

Oh and please remove the rtype comments for any signature you fix

@DanielNoord DanielNoord added this to the 2.16.0 milestone Apr 4, 2023
@DanielNoord DanielNoord added the Enhancement ✨ Improvement to a component label Apr 4, 2023
@nickdrozd
Copy link
Contributor Author

Is there some way to get Proxy to "count" as a NodeNG? That would solve a quite a few existing type errors.

@nickdrozd
Copy link
Contributor Author

nickdrozd commented Apr 4, 2023

Run Mypy and search the output for "Union[NodeNG, Proxy]" has no attribute.

@DanielNoord
Copy link
Collaborator

Is there some way to get Proxy to "count" as a NodeNG? That would solve a quite a few existing type errors.

Yes, by using SuccessfulInferenceResult πŸ˜„ Sadly there is no better way. NodeNG is simply incorrect.

@nickdrozd
Copy link
Contributor Author

I guess my question was partly rhetorical, since I am sure there must be a better way πŸ˜„ But I don't know what that better way is exactly.

A Proxy is just a stand-in for a real NodeNG, right? Or is it something else? The docstring is not very helpful: A simple proxy object.

But if it represents a real node, and can be called with all the same methods, then it ought to look like a real node to the type checker as well. SuccessfulInferenceResult appears to be a type alternative -- either this type or that type -- when really it's just a node or a node-alike, and those are practically the same thing.

At least that's my understanding of the situation.

@DanielNoord
Copy link
Collaborator

I guess my question was partly rhetorical, since I am sure there must be a better way smile But I don't know what that better way is exactly.

A Proxy is just a stand-in for a real NodeNG, right? Or is it something else? The docstring is not very helpful: A simple proxy object.

But if it represents a real node, and can be called with all the same methods, then it ought to look like a real node to the type checker as well. SuccessfulInferenceResult appears to be a type alternative -- either this type or that type -- when really it's just a node or a node-alike, and those are practically the same thing.

At least that's my understanding of the situation.

A Proxy can also be an Instance of something.

class A():
    ...

x = A()

x is now an Instance. It is essentially the same as a node indeed, but untangling the mess of Proxy.__getattr__ is something I don't want to burn myself on right now πŸ˜…

@nickdrozd nickdrozd marked this pull request as draft April 5, 2023 14:08
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.16.0, 3.0 Apr 24, 2023
@cdce8p cdce8p modified the milestones: 3.0.0a1, 3.0.0a2, 3.0.0a3 Apr 25, 2023
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 3.0.0a3, 3.0.0a4 May 14, 2023
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 3.0.0a4, 3.0.0a5, 3.0.0a6 Jun 6, 2023
@DanielNoord DanielNoord removed this from the 3.0.0a6 milestone Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants