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

Small refactor after 3.12 support #2227

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 30 additions & 22 deletions astroid/nodes/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2705,16 +2705,19 @@ class ParamSpec(_base_nodes.AssignTypeNode):
<ParamSpec l.1 at 0x7f23b2e4e198>
"""

_astroid_fields = ("name",)
Copy link
Member

Choose a reason for hiding this comment

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

Thanks, I missed these because I went back and forth on whether this should be a str or an AssignName until I saw the references for the similar issue with MatchStar and friends pointing to python/cpython#88160.


name: AssignName

def __init__(
self,
lineno: int,
col_offset: int,
parent: NodeNG,
*,
end_lineno: int | None = None,
end_col_offset: int | None = None,
end_lineno: int | None,
end_col_offset: int | None,
) -> None:
self.name: AssignName | None
super().__init__(
lineno=lineno,
col_offset=col_offset,
Expand All @@ -2723,7 +2726,7 @@ def __init__(
parent=parent,
)

def postinit(self, *, name: AssignName | None) -> None:
def postinit(self, *, name: AssignName) -> None:
self.name = name


Expand Down Expand Up @@ -3350,20 +3353,21 @@ class TypeAlias(_base_nodes.AssignTypeNode):
<TypeAlias l.1 at 0x7f23b2e4e198>
"""

_astroid_fields = ("type_params", "value")
_astroid_fields = ("name", "type_params", "value")

name: AssignName
type_params: list[TypeVar | ParamSpec | TypeVarTuple]
value: NodeNG
Comment on lines +3358 to +3360
Copy link
Member

Choose a reason for hiding this comment

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

I'm not totally sure why we're adopting this pattern instead of using the constructor.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't like it as well, but I do think we should at least try and keep one style so that we can then refactor it to a desired style all at once?

Copy link
Member

Choose a reason for hiding this comment

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

No worries. Sometimes it seems like we prefer not to mass-replace, but not a big deal, let's keep moving. πŸ‘


def __init__(
self,
lineno: int,
col_offset: int,
parent: NodeNG,
*,
end_lineno: int | None = None,
end_col_offset: int | None = None,
end_lineno: int | None,
end_col_offset: int | None,
) -> None:
self.name: AssignName | None
self.type_params: list[TypeVar, ParamSpec, TypeVarTuple]
self.value: NodeNG
super().__init__(
lineno=lineno,
col_offset=col_offset,
Expand All @@ -3375,8 +3379,8 @@ def __init__(
def postinit(
self,
*,
name: AssignName | None,
type_params: list[TypeVar, ParamSpec, TypeVarTuple],
name: AssignName,
type_params: list[TypeVar | ParamSpec | TypeVarTuple],
Comment on lines -3378 to +3383
Copy link
Member

Choose a reason for hiding this comment

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

Ouch, thank you, I was just working too quickly.

value: NodeNG,
) -> None:
self.name = name
Expand All @@ -3393,19 +3397,20 @@ class TypeVar(_base_nodes.AssignTypeNode):
<TypeVar l.1 at 0x7f23b2e4e198>
"""

_astroid_fields = ("bound",)
_astroid_fields = ("name", "bound")

name: AssignName
bound: NodeNG | None

def __init__(
self,
lineno: int,
col_offset: int,
parent: NodeNG,
*,
end_lineno: int | None = None,
end_col_offset: int | None = None,
end_lineno: int | None,
end_col_offset: int | None,
) -> None:
self.name: AssignName | None
self.bound: NodeNG | None
super().__init__(
lineno=lineno,
col_offset=col_offset,
Expand All @@ -3414,7 +3419,7 @@ def __init__(
parent=parent,
)

def postinit(self, *, name: AssignName | None, bound: NodeNG | None) -> None:
def postinit(self, *, name: AssignName, bound: NodeNG | None) -> None:
self.name = name
self.bound = bound

Expand All @@ -3428,16 +3433,19 @@ class TypeVarTuple(_base_nodes.AssignTypeNode):
<TypeVarTuple l.1 at 0x7f23b2e4e198>
"""

_astroid_fields = ("name",)

name: AssignName

def __init__(
self,
lineno: int,
col_offset: int,
parent: NodeNG,
*,
end_lineno: int | None = None,
end_col_offset: int | None = None,
end_lineno: int | None,
end_col_offset: int | None,
) -> None:
self.name: AssignName | None
super().__init__(
lineno=lineno,
col_offset=col_offset,
Expand All @@ -3446,7 +3454,7 @@ def __init__(
parent=parent,
)

def postinit(self, *, name: AssignName | None) -> None:
def postinit(self, *, name: AssignName) -> None:
self.name = name


Expand Down