Skip to content

Commit

Permalink
Merge branch 'main' into mandatory-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdrozd committed Dec 20, 2022
2 parents 590624a + 39d9caf commit f45afce
Show file tree
Hide file tree
Showing 22 changed files with 218 additions and 64 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: actions/checkout@v3.1.0
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
id: python
uses: actions/setup-python@v4.3.0
uses: actions/setup-python@v4.3.1
with:
python-version: ${{ env.DEFAULT_PYTHON }}
check-latest: true
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
uses: actions/checkout@v3.1.0
- name: Set up Python ${{ matrix.python-version }}
id: python
uses: actions/setup-python@v4.3.0
uses: actions/setup-python@v4.3.1
with:
python-version: ${{ matrix.python-version }}
check-latest: true
Expand Down Expand Up @@ -142,7 +142,7 @@ jobs:
uses: actions/checkout@v3.1.0
- name: Set up Python ${{ matrix.python-version }}
id: python
uses: actions/setup-python@v4.3.0
uses: actions/setup-python@v4.3.1
with:
python-version: ${{ matrix.python-version }}
check-latest: true
Expand Down Expand Up @@ -191,7 +191,7 @@ jobs:
uses: actions/checkout@v3.1.0
- name: Set up Python ${{ matrix.python-version }}
id: python
uses: actions/setup-python@v4.3.0
uses: actions/setup-python@v4.3.1
with:
python-version: ${{ matrix.python-version }}
check-latest: true
Expand Down Expand Up @@ -235,7 +235,7 @@ jobs:
uses: actions/checkout@v3.1.0
- name: Set up Python ${{ matrix.python-version }}
id: python
uses: actions/setup-python@v4.3.0
uses: actions/setup-python@v4.3.1
with:
python-version: ${{ matrix.python-version }}
check-latest: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: actions/checkout@v3.1.0
- name: Set up Python 3.9
id: python
uses: actions/setup-python@v4.3.0
uses: actions/setup-python@v4.3.1
with:
# virtualenv 15.1.0 cannot be installed on Python 3.10+
python-version: 3.9
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: actions/checkout@v3.1.0
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
id: python
uses: actions/setup-python@v4.3.0
uses: actions/setup-python@v4.3.1
with:
python-version: ${{ env.DEFAULT_PYTHON }}
check-latest: true
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ ci:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
exclude: .github/|tests/testdata
- id: end-of-file-fixer
exclude: tests/testdata
- repo: https://github.com/PyCQA/autoflake
rev: v1.7.7
rev: v2.0.0
hooks:
- id: autoflake
exclude: tests/testdata|astroid/__init__.py|astroid/scoped_nodes.py|astroid/node_classes.py
Expand Down Expand Up @@ -44,7 +44,7 @@ repos:
- id: black-disable-checker
exclude: tests/unittest_nodes_lineno.py
- repo: https://github.com/psf/black
rev: 22.10.0
rev: 22.12.0
hooks:
- id: black
args: [--safe, --quiet]
Expand Down
16 changes: 16 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ Release date: TBA

Refs PyCQA/pylint#2567

What's New in astroid 2.12.14?
==============================
Release date: TBA

* Handle the effect of properties on the ``__init__`` of a dataclass correctly.

Closes PyCQA/pylint#5225

* Fix crash if ``numpy`` module doesn't have ``version`` attribute.

Refs PyCQA/pylint#7868

* Handle ``AttributeError`` during ``str.format`` template inference tip evaluation

Closes PyCQA/pylint#1902

What's New in astroid 2.12.13?
==============================
Release date: 2022-11-19
Expand Down
2 changes: 2 additions & 0 deletions astroid/_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ast
import sys
import types
from collections.abc import Callable
from functools import partial
from typing import NamedTuple

Expand Down Expand Up @@ -36,6 +37,7 @@ class ParserModule(NamedTuple):
context_classes: dict[type[ast.expr_context], Context]

def parse(self, string: str, type_comments: bool = True) -> ast.Module:
parse_func: Callable[[str], ast.Module]
if self.module is _ast_py3:
if PY38_PLUS:
parse_func = partial(self.module.parse, type_comments=type_comments)
Expand Down
5 changes: 3 additions & 2 deletions astroid/brain/brain_builtin_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def _builtin_filter_predicate(node, builtin_name) -> bool:
return False


def register_builtin_transform(transform, builtin_name):
def register_builtin_transform(transform, builtin_name) -> None:
"""Register a new transform function for the given *builtin_name*.
The transform function must accept two parameters, a node and
Expand Down Expand Up @@ -952,7 +952,8 @@ def _infer_str_format_call(

try:
formatted_string = format_template.format(*pos_values, **keyword_values)
except (IndexError, KeyError, TypeError, ValueError):
except (AttributeError, IndexError, KeyError, TypeError, ValueError):
# AttributeError: processing a replacement field using the arguments failed
# IndexError: there are too few arguments to interpolate
# TypeError: Unsupported format string
# ValueError: Unknown format code
Expand Down
19 changes: 19 additions & 0 deletions astroid/brain/brain_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,17 @@ def _generate_dataclass_init(
name, annotation, value = assign.target.name, assign.annotation, assign.value
assign_names.append(name)

# Check whether this assign is overriden by a property assignment
property_node: nodes.FunctionDef | None = None
for additional_assign in node.locals[name]:
if not isinstance(additional_assign, nodes.FunctionDef):
continue
if not additional_assign.decorators:
continue
if "builtins.property" in additional_assign.decoratornames():
property_node = additional_assign
break

if _is_init_var(annotation): # type: ignore[arg-type] # annotation is never None
init_var = True
if isinstance(annotation, nodes.Subscript):
Expand Down Expand Up @@ -277,6 +288,14 @@ def _generate_dataclass_init(
)
else:
param_str += f" = {value.as_string()}"
elif property_node:
# We set the result of the property call as default
# This hides the fact that this would normally be a 'property object'
# But we can't represent those as string
try:
param_str += f" = {next(property_node.infer_call_result()).as_string()}"
except (InferenceError, StopIteration):
pass

params.append(param_str)
if not init_var:
Expand Down
2 changes: 1 addition & 1 deletion astroid/brain/brain_numpy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _get_numpy_version() -> tuple[str, str, str]:
import numpy # pylint: disable=import-outside-toplevel

return tuple(numpy.version.version.split("."))
except ImportError:
except (ImportError, AttributeError):
return ("0", "0", "0")


Expand Down
2 changes: 1 addition & 1 deletion astroid/brain/brain_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from astroid.nodes.scoped_nodes import ClassDef


def _patch_uuid_class(node):
def _patch_uuid_class(node: ClassDef) -> None:
# The .int member is patched using __dict__
node.locals["int"] = [Const(0, parent=node)]

Expand Down
11 changes: 9 additions & 2 deletions astroid/brain/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@
# For details: https://github.com/PyCQA/astroid/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt

from __future__ import annotations

from collections.abc import Callable

from astroid.manager import AstroidManager
from astroid.nodes.scoped_nodes import Module


def register_module_extender(manager, module_name, get_extension_mod):
def transform(node):
def register_module_extender(
manager: AstroidManager, module_name: str, get_extension_mod: Callable[[], Module]
) -> None:
def transform(node: Module) -> None:
extension_module = get_extension_mod()
for name, objs in extension_module.locals.items():
node.locals[name] = objs
Expand Down
6 changes: 4 additions & 2 deletions astroid/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import inspect
import sys
import warnings
from collections.abc import Callable
from collections.abc import Callable, Generator
from typing import TypeVar

import wrapt
Expand Down Expand Up @@ -97,7 +97,9 @@ def path_wrapper(func):
"""

@functools.wraps(func)
def wrapped(node, context: InferenceContext | None = None, _func=func, **kwargs):
def wrapped(
node, context: InferenceContext | None = None, _func=func, **kwargs
) -> Generator:
"""wrapper function handling context"""
if context is None:
context = InferenceContext()
Expand Down

0 comments on commit f45afce

Please sign in to comment.